@settlemint/sdk-portal 1.1.9-pr8fb2521f → 1.1.9-pr9c4cb566

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:118](https://github.com/settlemint/sdk/blob/v1.1.9/sdk/portal/src/portal.ts#L118)
57
+ Defined in: [sdk/portal/src/portal.ts:108](https://github.com/settlemint/sdk/blob/v1.1.9/sdk/portal/src/portal.ts#L108)
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:122](https://github.com/settlemint/sdk/blob/v1.1.9/sdk/portal/src/portal.ts#L122) |
83
- | `graphql` | `initGraphQLTada`\<`Setup`\> | [sdk/portal/src/portal.ts:123](https://github.com/settlemint/sdk/blob/v1.1.9/sdk/portal/src/portal.ts#L123) |
82
+ | `client` | `GraphQLClient` | [sdk/portal/src/portal.ts:112](https://github.com/settlemint/sdk/blob/v1.1.9/sdk/portal/src/portal.ts#L112) |
83
+ | `graphql` | `initGraphQLTada`\<`Setup`\> | [sdk/portal/src/portal.ts:113](https://github.com/settlemint/sdk/blob/v1.1.9/sdk/portal/src/portal.ts#L113) |
84
84
 
85
85
  ##### Throws
86
86
 
@@ -97,13 +97,8 @@ export const { client: portalClient, graphql: portalGraphql } = createPortalClie
97
97
  introspection: introspection;
98
98
  disableMasking: true;
99
99
  scalars: {
100
- DateTime: Date;
101
- JSON: Record<string, unknown>;
102
- Bytes: string;
103
- Int8: string;
104
- BigInt: string;
105
- BigDecimal: string;
106
- Timestamp: string;
100
+ // Change unknown to the type you are using to store metadata
101
+ JSON: unknown;
107
102
  };
108
103
  }>({
109
104
  instance: process.env.SETTLEMINT_PORTAL_GRAPHQL_ENDPOINT,
@@ -116,13 +111,8 @@ export const { client: portalBrowserClient, graphql: portalBrowserGraphql } = cr
116
111
  introspection: introspection;
117
112
  disableMasking: true;
118
113
  scalars: {
119
- DateTime: Date;
120
- JSON: Record<string, unknown>;
121
- Bytes: string;
122
- Int8: string;
123
- BigInt: string;
124
- BigDecimal: string;
125
- Timestamp: string;
114
+ // Change unknown to the type you are using to store metadata
115
+ JSON: unknown;
126
116
  };
127
117
  }>({});
128
118
 
@@ -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 * 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"]}
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 * // Change unknown to the type you are using to store metadata\n * JSON: unknown;\n * };\n * }>({\n * instance: process.env.SETTLEMINT_PORTAL_GRAPHQL_ENDPOINT,\n * 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 * // Change unknown to the type you are using to store metadata\n * JSON: unknown;\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;AA8HlB,IAAAA,cAA6B;AAnHtB,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;AAiDO,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.d.cts CHANGED
@@ -51,13 +51,8 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
51
51
  * introspection: introspection;
52
52
  * disableMasking: true;
53
53
  * scalars: {
54
- * DateTime: Date;
55
- * JSON: Record<string, unknown>;
56
- * Bytes: string;
57
- * Int8: string;
58
- * BigInt: string;
59
- * BigDecimal: string;
60
- * Timestamp: string;
54
+ * // Change unknown to the type you are using to store metadata
55
+ * JSON: unknown;
61
56
  * };
62
57
  * }>({
63
58
  * instance: process.env.SETTLEMINT_PORTAL_GRAPHQL_ENDPOINT,
@@ -70,13 +65,8 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
70
65
  * introspection: introspection;
71
66
  * disableMasking: true;
72
67
  * scalars: {
73
- * DateTime: Date;
74
- * JSON: Record<string, unknown>;
75
- * Bytes: string;
76
- * Int8: string;
77
- * BigInt: string;
78
- * BigDecimal: string;
79
- * Timestamp: string;
68
+ * // Change unknown to the type you are using to store metadata
69
+ * JSON: unknown;
80
70
  * };
81
71
  * }>({});
82
72
  *
package/dist/portal.d.ts CHANGED
@@ -51,13 +51,8 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
51
51
  * introspection: introspection;
52
52
  * disableMasking: true;
53
53
  * scalars: {
54
- * DateTime: Date;
55
- * JSON: Record<string, unknown>;
56
- * Bytes: string;
57
- * Int8: string;
58
- * BigInt: string;
59
- * BigDecimal: string;
60
- * Timestamp: string;
54
+ * // Change unknown to the type you are using to store metadata
55
+ * JSON: unknown;
61
56
  * };
62
57
  * }>({
63
58
  * instance: process.env.SETTLEMINT_PORTAL_GRAPHQL_ENDPOINT,
@@ -70,13 +65,8 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
70
65
  * introspection: introspection;
71
66
  * disableMasking: true;
72
67
  * scalars: {
73
- * DateTime: Date;
74
- * JSON: Record<string, unknown>;
75
- * Bytes: string;
76
- * Int8: string;
77
- * BigInt: string;
78
- * BigDecimal: string;
79
- * Timestamp: string;
68
+ * // Change unknown to the type you are using to store metadata
69
+ * JSON: unknown;
80
70
  * };
81
71
  * }>({});
82
72
  *
@@ -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 * 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":[]}
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 * // Change unknown to the type you are using to store metadata\n * JSON: unknown;\n * };\n * }>({\n * instance: process.env.SETTLEMINT_PORTAL_GRAPHQL_ENDPOINT,\n * 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 * // Change unknown to the type you are using to store metadata\n * JSON: unknown;\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;AA8HlB,SAAS,oBAAoB;AAnHtB,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;AAiDO,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.9-pr8fb2521f",
4
+ "version": "1.1.9-pr9c4cb566",
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-pr8fb2521f",
55
+ "@settlemint/sdk-utils": "1.1.9-pr9c4cb566",
56
56
  "graphql-request": "^7",
57
57
  "zod": "^3"
58
58
  },