@settlemint/sdk-portal 1.1.2 → 1.1.3-main3dbd1505

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
@@ -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:101](https://github.com/settlemint/sdk/blob/v1.1.2/sdk/portal/src/portal.ts#L101)
57
+ Defined in: [sdk/portal/src/portal.ts:118](https://github.com/settlemint/sdk/blob/v1.1.3/sdk/portal/src/portal.ts#L118)
58
58
 
59
59
  Creates a Portal GraphQL client with the provided configuration.
60
60
 
@@ -79,8 +79,8 @@ An object containing the configured GraphQL client and graphql helper function
79
79
 
80
80
  | Name | Type | Defined in |
81
81
  | ------ | ------ | ------ |
82
- | `client` | `GraphQLClient` | [sdk/portal/src/portal.ts:105](https://github.com/settlemint/sdk/blob/v1.1.2/sdk/portal/src/portal.ts#L105) |
83
- | `graphql` | `initGraphQLTada`\<`Setup`\> | [sdk/portal/src/portal.ts:106](https://github.com/settlemint/sdk/blob/v1.1.2/sdk/portal/src/portal.ts#L106) |
82
+ | `client` | `GraphQLClient` | [sdk/portal/src/portal.ts:122](https://github.com/settlemint/sdk/blob/v1.1.3/sdk/portal/src/portal.ts#L122) |
83
+ | `graphql` | `initGraphQLTada`\<`Setup`\> | [sdk/portal/src/portal.ts:123](https://github.com/settlemint/sdk/blob/v1.1.3/sdk/portal/src/portal.ts#L123) |
84
84
 
85
85
  ##### Throws
86
86
 
@@ -144,7 +144,7 @@ const result = await client.request(query);
144
144
 
145
145
  > **ClientOptions**: \{ `accessToken`: `string`; `instance`: `string`; `runtime`: `"server"`; \} \| \{ `runtime`: `"browser"`; \}
146
146
 
147
- Defined in: [sdk/portal/src/portal.ts:30](https://github.com/settlemint/sdk/blob/v1.1.2/sdk/portal/src/portal.ts#L30)
147
+ Defined in: [sdk/portal/src/portal.ts:30](https://github.com/settlemint/sdk/blob/v1.1.3/sdk/portal/src/portal.ts#L30)
148
148
 
149
149
  Type representing the validated client options.
150
150
 
@@ -154,7 +154,7 @@ Type representing the validated client options.
154
154
 
155
155
  > **RequestConfig**: `ConstructorParameters`\<*typeof* `GraphQLClient`\>\[`1`\]
156
156
 
157
- Defined in: [sdk/portal/src/portal.ts:10](https://github.com/settlemint/sdk/blob/v1.1.2/sdk/portal/src/portal.ts#L10)
157
+ Defined in: [sdk/portal/src/portal.ts:10](https://github.com/settlemint/sdk/blob/v1.1.3/sdk/portal/src/portal.ts#L10)
158
158
 
159
159
  Configuration options for the GraphQL client, excluding 'url' and 'exchanges'.
160
160
 
@@ -164,7 +164,7 @@ Configuration options for the GraphQL client, excluding 'url' and 'exchanges'.
164
164
 
165
165
  > `const` **ClientOptionsSchema**: `ZodDiscriminatedUnion`\<[`ClientOptions`](README.md#clientoptions)\>
166
166
 
167
- Defined in: [sdk/portal/src/portal.ts:16](https://github.com/settlemint/sdk/blob/v1.1.2/sdk/portal/src/portal.ts#L16)
167
+ Defined in: [sdk/portal/src/portal.ts:16](https://github.com/settlemint/sdk/blob/v1.1.3/sdk/portal/src/portal.ts#L16)
168
168
 
169
169
  Schema for validating Portal client configuration options.
170
170
  Discriminates between server and browser runtime environments.
package/dist/portal.cjs CHANGED
@@ -44,6 +44,16 @@ var ClientOptionsSchema = import_zod.z.discriminatedUnion("runtime", [
44
44
  function getFullUrl(options) {
45
45
  return options.runtime === "server" ? new URL(options.instance).toString() : new URL("/proxy/portal/graphql", window?.location?.origin ?? "http://localhost:3000").toString();
46
46
  }
47
+ function getHeaders(options) {
48
+ if (options.runtime === "server") {
49
+ return {
50
+ headers: {
51
+ "x-auth-token": options.accessToken
52
+ }
53
+ };
54
+ }
55
+ return {};
56
+ }
47
57
  function createPortalClient(options, clientOptions) {
48
58
  const validatedOptions = (0, import_validation.validate)(ClientOptionsSchema, {
49
59
  ...options,
@@ -54,11 +64,7 @@ function createPortalClient(options, clientOptions) {
54
64
  return {
55
65
  client: new import_graphql_request.GraphQLClient(fullUrl, {
56
66
  ...clientOptions,
57
- ...validatedOptions.runtime === "server" && {
58
- headers: {
59
- "x-auth-token": validatedOptions.accessToken
60
- }
61
- }
67
+ ...getHeaders(validatedOptions)
62
68
  }),
63
69
  graphql
64
70
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/portal.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 * 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 * Discriminates between server and browser runtime environments.\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 representing the validated client options.\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\n\n/**\n * Constructs the Portal GraphQL endpoint URL based on runtime environment.\n *\n * @param options - The validated client options\n * @returns The complete GraphQL endpoint URL\n */\nfunction getFullUrl(options: ClientOptions): string {\n return options.runtime === \"server\"\n ? new URL(options.instance).toString()\n : new URL(\"/proxy/portal/graphql\", window?.location?.origin ?? \"http://localhost:3000\").toString();\n}\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 * // Server-side usage\n * export const { client: portalClient, graphql: portalGraphql } = createPortalClient<{\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_PORTAL_GRAPHQL_ENDPOINT,\n * runtime: \"server\",\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * });\n *\n * // Browser-side usage\n * export const { client: portalBrowserClient, graphql: portalBrowserGraphql } = createPortalClient<{\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 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: 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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA6B;AAC7B,wBAAwE;AACxE,iBAA0D;AAC1D,6BAA8B;AAC9B,iBAAkB;AA2HlB,IAAAA,cAA6B;AAhHtB,IAAM,sBAAsB,aAAE,mBAAmB,WAAW;AAAA,EACjE,aAAE,OAAO;AAAA,IACP,UAAU;AAAA,IACV,SAAS,aAAE,QAAQ,QAAQ;AAAA,IAC3B,aAAa;AAAA,EACf,CAAC;AAAA,EACD,aAAE,OAAO;AAAA,IACP,SAAS,aAAE,QAAQ,SAAS;AAAA,EAC9B,CAAC;AACH,CAAC;AAaD,SAAS,WAAW,SAAgC;AAClD,SAAO,QAAQ,YAAY,WACvB,IAAI,IAAI,QAAQ,QAAQ,EAAE,SAAS,IACnC,IAAI,IAAI,yBAAyB,QAAQ,UAAU,UAAU,uBAAuB,EAAE,SAAS;AACrG;AA2DO,SAAS,mBACd,SACA,eAIA;AACA,QAAM,uBAAmB,4BAAS,qBAAqB;AAAA,IACrD,GAAG;AAAA,IACH,SAAS,8BAAe,WAAW;AAAA,EACrC,CAAC;AACD,QAAM,cAAU,4BAAuB;AACvC,QAAM,UAAU,WAAW,gBAAgB;AAE3C,SAAO;AAAA,IACL,QAAQ,IAAI,qCAAc,SAAS;AAAA,MACjC,GAAG;AAAA,MACH,GAAI,iBAAiB,YAAY,YAAY;AAAA,QAC3C,SAAS;AAAA,UACP,gBAAgB,iBAAiB;AAAA,QACnC;AAAA,MACF;AAAA,IACF,CAAC;AAAA,IACD;AAAA,EACF;AACF;","names":["import_gql"]}
1
+ {"version":3,"sources":["../src/portal.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 * 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 * Discriminates between server and browser runtime environments.\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 representing the validated client options.\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\n\n/**\n * Constructs the Portal GraphQL endpoint URL based on runtime environment.\n *\n * @param options - The validated client options\n * @returns The complete GraphQL endpoint URL\n */\nfunction getFullUrl(options: ClientOptions): string {\n return options.runtime === \"server\"\n ? new URL(options.instance).toString()\n : new URL(\"/proxy/portal/graphql\", window?.location?.origin ?? \"http://localhost:3000\").toString();\n}\n\n/**\n * Gets the headers configuration based on runtime options\n *\n * @param options - The validated client options\n * @returns Headers configuration object or empty object\n */\nfunction getHeaders(options: ClientOptions): Record<string, unknown> {\n if (options.runtime === \"server\") {\n return {\n headers: {\n \"x-auth-token\": options.accessToken,\n },\n };\n }\n return {};\n}\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 * // Server-side usage\n * export const { client: portalClient, graphql: portalGraphql } = createPortalClient<{\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_PORTAL_GRAPHQL_ENDPOINT,\n * runtime: \"server\",\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * });\n *\n * // Browser-side usage\n * export const { client: portalBrowserClient, graphql: portalBrowserGraphql } = createPortalClient<{\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 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: 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 ...getHeaders(validatedOptions),\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;AAwIlB,IAAAA,cAA6B;AA7HtB,IAAM,sBAAsB,aAAE,mBAAmB,WAAW;AAAA,EACjE,aAAE,OAAO;AAAA,IACP,UAAU;AAAA,IACV,SAAS,aAAE,QAAQ,QAAQ;AAAA,IAC3B,aAAa;AAAA,EACf,CAAC;AAAA,EACD,aAAE,OAAO;AAAA,IACP,SAAS,aAAE,QAAQ,SAAS;AAAA,EAC9B,CAAC;AACH,CAAC;AAaD,SAAS,WAAW,SAAgC;AAClD,SAAO,QAAQ,YAAY,WACvB,IAAI,IAAI,QAAQ,QAAQ,EAAE,SAAS,IACnC,IAAI,IAAI,yBAAyB,QAAQ,UAAU,UAAU,uBAAuB,EAAE,SAAS;AACrG;AAQA,SAAS,WAAW,SAAiD;AACnE,MAAI,QAAQ,YAAY,UAAU;AAChC,WAAO;AAAA,MACL,SAAS;AAAA,QACP,gBAAgB,QAAQ;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AACA,SAAO,CAAC;AACV;AA2DO,SAAS,mBACd,SACA,eAIA;AACA,QAAM,uBAAmB,4BAAS,qBAAqB;AAAA,IACrD,GAAG;AAAA,IACH,SAAS,8BAAe,WAAW;AAAA,EACrC,CAAC;AACD,QAAM,cAAU,4BAAuB;AACvC,QAAM,UAAU,WAAW,gBAAgB;AAE3C,SAAO;AAAA,IACL,QAAQ,IAAI,qCAAc,SAAS;AAAA,MACjC,GAAG;AAAA,MACH,GAAG,WAAW,gBAAgB;AAAA,IAChC,CAAC;AAAA,IACD;AAAA,EACF;AACF;","names":["import_gql"]}
package/dist/portal.mjs CHANGED
@@ -18,6 +18,16 @@ var ClientOptionsSchema = z.discriminatedUnion("runtime", [
18
18
  function getFullUrl(options) {
19
19
  return options.runtime === "server" ? new URL(options.instance).toString() : new URL("/proxy/portal/graphql", window?.location?.origin ?? "http://localhost:3000").toString();
20
20
  }
21
+ function getHeaders(options) {
22
+ if (options.runtime === "server") {
23
+ return {
24
+ headers: {
25
+ "x-auth-token": options.accessToken
26
+ }
27
+ };
28
+ }
29
+ return {};
30
+ }
21
31
  function createPortalClient(options, clientOptions) {
22
32
  const validatedOptions = validate(ClientOptionsSchema, {
23
33
  ...options,
@@ -28,11 +38,7 @@ function createPortalClient(options, clientOptions) {
28
38
  return {
29
39
  client: new GraphQLClient(fullUrl, {
30
40
  ...clientOptions,
31
- ...validatedOptions.runtime === "server" && {
32
- headers: {
33
- "x-auth-token": validatedOptions.accessToken
34
- }
35
- }
41
+ ...getHeaders(validatedOptions)
36
42
  }),
37
43
  graphql
38
44
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/portal.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 * 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 * Discriminates between server and browser runtime environments.\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 representing the validated client options.\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\n\n/**\n * Constructs the Portal GraphQL endpoint URL based on runtime environment.\n *\n * @param options - The validated client options\n * @returns The complete GraphQL endpoint URL\n */\nfunction getFullUrl(options: ClientOptions): string {\n return options.runtime === \"server\"\n ? new URL(options.instance).toString()\n : new URL(\"/proxy/portal/graphql\", window?.location?.origin ?? \"http://localhost:3000\").toString();\n}\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 * // Server-side usage\n * export const { client: portalClient, graphql: portalGraphql } = createPortalClient<{\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_PORTAL_GRAPHQL_ENDPOINT,\n * runtime: \"server\",\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * });\n *\n * // Browser-side usage\n * export const { client: portalBrowserClient, graphql: portalBrowserGraphql } = createPortalClient<{\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 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: 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,SAAS,oBAAoB;AAC7B,SAAS,8BAA8B,iBAAiB,gBAAgB;AACxE,SAAmC,uBAAuB;AAC1D,SAAS,qBAAqB;AAC9B,SAAS,SAAS;AA2HlB,SAAS,oBAAoB;AAhHtB,IAAM,sBAAsB,EAAE,mBAAmB,WAAW;AAAA,EACjE,EAAE,OAAO;AAAA,IACP,UAAU;AAAA,IACV,SAAS,EAAE,QAAQ,QAAQ;AAAA,IAC3B,aAAa;AAAA,EACf,CAAC;AAAA,EACD,EAAE,OAAO;AAAA,IACP,SAAS,EAAE,QAAQ,SAAS;AAAA,EAC9B,CAAC;AACH,CAAC;AAaD,SAAS,WAAW,SAAgC;AAClD,SAAO,QAAQ,YAAY,WACvB,IAAI,IAAI,QAAQ,QAAQ,EAAE,SAAS,IACnC,IAAI,IAAI,yBAAyB,QAAQ,UAAU,UAAU,uBAAuB,EAAE,SAAS;AACrG;AA2DO,SAAS,mBACd,SACA,eAIA;AACA,QAAM,mBAAmB,SAAS,qBAAqB;AAAA,IACrD,GAAG;AAAA,IACH,SAAS,eAAe,WAAW;AAAA,EACrC,CAAC;AACD,QAAM,UAAU,gBAAuB;AACvC,QAAM,UAAU,WAAW,gBAAgB;AAE3C,SAAO;AAAA,IACL,QAAQ,IAAI,cAAc,SAAS;AAAA,MACjC,GAAG;AAAA,MACH,GAAI,iBAAiB,YAAY,YAAY;AAAA,QAC3C,SAAS;AAAA,UACP,gBAAgB,iBAAiB;AAAA,QACnC;AAAA,MACF;AAAA,IACF,CAAC;AAAA,IACD;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/portal.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 * 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 * Discriminates between server and browser runtime environments.\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 representing the validated client options.\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\n\n/**\n * Constructs the Portal GraphQL endpoint URL based on runtime environment.\n *\n * @param options - The validated client options\n * @returns The complete GraphQL endpoint URL\n */\nfunction getFullUrl(options: ClientOptions): string {\n return options.runtime === \"server\"\n ? new URL(options.instance).toString()\n : new URL(\"/proxy/portal/graphql\", window?.location?.origin ?? \"http://localhost:3000\").toString();\n}\n\n/**\n * Gets the headers configuration based on runtime options\n *\n * @param options - The validated client options\n * @returns Headers configuration object or empty object\n */\nfunction getHeaders(options: ClientOptions): Record<string, unknown> {\n if (options.runtime === \"server\") {\n return {\n headers: {\n \"x-auth-token\": options.accessToken,\n },\n };\n }\n return {};\n}\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 * // Server-side usage\n * export const { client: portalClient, graphql: portalGraphql } = createPortalClient<{\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_PORTAL_GRAPHQL_ENDPOINT,\n * runtime: \"server\",\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * });\n *\n * // Browser-side usage\n * export const { client: portalBrowserClient, graphql: portalBrowserGraphql } = createPortalClient<{\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 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: 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 ...getHeaders(validatedOptions),\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;AAwIlB,SAAS,oBAAoB;AA7HtB,IAAM,sBAAsB,EAAE,mBAAmB,WAAW;AAAA,EACjE,EAAE,OAAO;AAAA,IACP,UAAU;AAAA,IACV,SAAS,EAAE,QAAQ,QAAQ;AAAA,IAC3B,aAAa;AAAA,EACf,CAAC;AAAA,EACD,EAAE,OAAO;AAAA,IACP,SAAS,EAAE,QAAQ,SAAS;AAAA,EAC9B,CAAC;AACH,CAAC;AAaD,SAAS,WAAW,SAAgC;AAClD,SAAO,QAAQ,YAAY,WACvB,IAAI,IAAI,QAAQ,QAAQ,EAAE,SAAS,IACnC,IAAI,IAAI,yBAAyB,QAAQ,UAAU,UAAU,uBAAuB,EAAE,SAAS;AACrG;AAQA,SAAS,WAAW,SAAiD;AACnE,MAAI,QAAQ,YAAY,UAAU;AAChC,WAAO;AAAA,MACL,SAAS;AAAA,QACP,gBAAgB,QAAQ;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AACA,SAAO,CAAC;AACV;AA2DO,SAAS,mBACd,SACA,eAIA;AACA,QAAM,mBAAmB,SAAS,qBAAqB;AAAA,IACrD,GAAG;AAAA,IACH,SAAS,eAAe,WAAW;AAAA,EACrC,CAAC;AACD,QAAM,UAAU,gBAAuB;AACvC,QAAM,UAAU,WAAW,gBAAgB;AAE3C,SAAO;AAAA,IACL,QAAQ,IAAI,cAAc,SAAS;AAAA,MACjC,GAAG;AAAA,MACH,GAAG,WAAW,gBAAgB;AAAA,IAChC,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": "1.1.2",
4
+ "version": "1.1.3-main3dbd1505",
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.2",
55
+ "@settlemint/sdk-utils": "1.1.3-main3dbd1505",
56
56
  "graphql-request": "^7",
57
57
  "zod": "^3"
58
58
  },