@settlemint/sdk-portal 1.1.12 → 1.1.14-main4e68a067

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:108](https://github.com/settlemint/sdk/blob/v1.1.12/sdk/portal/src/portal.ts#L108)
57
+ Defined in: [sdk/portal/src/portal.ts:110](https://github.com/settlemint/sdk/blob/v1.1.14/sdk/portal/src/portal.ts#L110)
58
58
 
59
59
  Creates a Portal GraphQL client with the provided configuration.
60
60
 
@@ -68,7 +68,7 @@ Creates a Portal GraphQL client with the provided configuration.
68
68
 
69
69
  | Parameter | Type | Description |
70
70
  | ------ | ------ | ------ |
71
- | `options` | `Omit`\<\{ `accessToken`: `string`; `instance`: `string`; `runtime`: `"server"`; \} \| \{ `runtime`: `"browser"`; \}, `"runtime"`\> & `Record`\<`string`, `unknown`\> | Configuration options for the Portal client |
71
+ | `options` | `Omit`\<\{ `accessToken`: `string`; `cache`: `"default"` \| `"force-cache"` \| `"no-cache"` \| `"no-store"` \| `"only-if-cached"` \| `"reload"`; `instance`: `string`; `runtime`: `"server"`; \} \| \{ `cache`: `"default"` \| `"force-cache"` \| `"no-cache"` \| `"no-store"` \| `"only-if-cached"` \| `"reload"`; `runtime`: `"browser"`; \}, `"runtime"`\> & `Record`\<`string`, `unknown`\> | Configuration options for the Portal client |
72
72
  | `clientOptions`? | `RequestConfig` | Additional GraphQL client configuration options |
73
73
 
74
74
  ##### Returns
@@ -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:112](https://github.com/settlemint/sdk/blob/v1.1.12/sdk/portal/src/portal.ts#L112) |
83
- | `graphql` | `initGraphQLTada`\<`Setup`\> | [sdk/portal/src/portal.ts:113](https://github.com/settlemint/sdk/blob/v1.1.12/sdk/portal/src/portal.ts#L113) |
82
+ | `client` | `GraphQLClient` | [sdk/portal/src/portal.ts:114](https://github.com/settlemint/sdk/blob/v1.1.14/sdk/portal/src/portal.ts#L114) |
83
+ | `graphql` | `initGraphQLTada`\<`Setup`\> | [sdk/portal/src/portal.ts:115](https://github.com/settlemint/sdk/blob/v1.1.14/sdk/portal/src/portal.ts#L115) |
84
84
 
85
85
  ##### Throws
86
86
 
@@ -132,9 +132,9 @@ const result = await client.request(query);
132
132
 
133
133
  #### ClientOptions
134
134
 
135
- > **ClientOptions**: \{ `accessToken`: `string`; `instance`: `string`; `runtime`: `"server"`; \} \| \{ `runtime`: `"browser"`; \}
135
+ > **ClientOptions**: \{ `accessToken`: `string`; `cache`: `"default"` \| `"force-cache"` \| `"no-cache"` \| `"no-store"` \| `"only-if-cached"` \| `"reload"`; `instance`: `string`; `runtime`: `"server"`; \} \| \{ `cache`: `"default"` \| `"force-cache"` \| `"no-cache"` \| `"no-store"` \| `"only-if-cached"` \| `"reload"`; `runtime`: `"browser"`; \}
136
136
 
137
- Defined in: [sdk/portal/src/portal.ts:30](https://github.com/settlemint/sdk/blob/v1.1.12/sdk/portal/src/portal.ts#L30)
137
+ Defined in: [sdk/portal/src/portal.ts:32](https://github.com/settlemint/sdk/blob/v1.1.14/sdk/portal/src/portal.ts#L32)
138
138
 
139
139
  Type representing the validated client options.
140
140
 
@@ -144,7 +144,7 @@ Type representing the validated client options.
144
144
 
145
145
  > **RequestConfig**: `ConstructorParameters`\<*typeof* `GraphQLClient`\>\[`1`\]
146
146
 
147
- Defined in: [sdk/portal/src/portal.ts:10](https://github.com/settlemint/sdk/blob/v1.1.12/sdk/portal/src/portal.ts#L10)
147
+ Defined in: [sdk/portal/src/portal.ts:10](https://github.com/settlemint/sdk/blob/v1.1.14/sdk/portal/src/portal.ts#L10)
148
148
 
149
149
  Configuration options for the GraphQL client, excluding 'url' and 'exchanges'.
150
150
 
@@ -154,7 +154,7 @@ Configuration options for the GraphQL client, excluding 'url' and 'exchanges'.
154
154
 
155
155
  > `const` **ClientOptionsSchema**: `ZodDiscriminatedUnion`\<[`ClientOptions`](README.md#clientoptions)\>
156
156
 
157
- Defined in: [sdk/portal/src/portal.ts:16](https://github.com/settlemint/sdk/blob/v1.1.12/sdk/portal/src/portal.ts#L16)
157
+ Defined in: [sdk/portal/src/portal.ts:16](https://github.com/settlemint/sdk/blob/v1.1.14/sdk/portal/src/portal.ts#L16)
158
158
 
159
159
  Schema for validating Portal client configuration options.
160
160
  Discriminates between server and browser runtime environments.
package/dist/portal.cjs CHANGED
@@ -35,10 +35,12 @@ var ClientOptionsSchema = import_zod.z.discriminatedUnion("runtime", [
35
35
  import_zod.z.object({
36
36
  instance: import_validation.UrlOrPathSchema,
37
37
  runtime: import_zod.z.literal("server"),
38
- accessToken: import_validation.ApplicationAccessTokenSchema
38
+ accessToken: import_validation.ApplicationAccessTokenSchema,
39
+ cache: import_zod.z.enum(["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]).optional()
39
40
  }),
40
41
  import_zod.z.object({
41
- runtime: import_zod.z.literal("browser")
42
+ runtime: import_zod.z.literal("browser"),
43
+ cache: import_zod.z.enum(["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]).optional()
42
44
  })
43
45
  ]);
44
46
  function getFullUrl(options) {
@@ -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 * // 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"]}
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 cache: z.enum([\"default\", \"force-cache\", \"no-cache\", \"no-store\", \"only-if-cached\", \"reload\"]).optional(),\n }),\n z.object({\n runtime: z.literal(\"browser\"),\n cache: z.enum([\"default\", \"force-cache\", \"no-cache\", \"no-store\", \"only-if-cached\", \"reload\"]).optional(),\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;AAgIlB,IAAAA,cAA6B;AArHtB,IAAM,sBAAsB,aAAE,mBAAmB,WAAW;AAAA,EACjE,aAAE,OAAO;AAAA,IACP,UAAU;AAAA,IACV,SAAS,aAAE,QAAQ,QAAQ;AAAA,IAC3B,aAAa;AAAA,IACb,OAAO,aAAE,KAAK,CAAC,WAAW,eAAe,YAAY,YAAY,kBAAkB,QAAQ,CAAC,EAAE,SAAS;AAAA,EACzG,CAAC;AAAA,EACD,aAAE,OAAO;AAAA,IACP,SAAS,aAAE,QAAQ,SAAS;AAAA,IAC5B,OAAO,aAAE,KAAK,CAAC,WAAW,eAAe,YAAY,YAAY,kBAAkB,QAAQ,CAAC,EAAE,SAAS;AAAA,EACzG,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
@@ -15,20 +15,26 @@ declare const ClientOptionsSchema: z.ZodDiscriminatedUnion<"runtime", [z.ZodObje
15
15
  instance: z.ZodUnion<[z.ZodString, z.ZodString]>;
16
16
  runtime: z.ZodLiteral<"server">;
17
17
  accessToken: z.ZodString;
18
+ cache: z.ZodOptional<z.ZodEnum<["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]>>;
18
19
  }, "strip", z.ZodTypeAny, {
19
20
  runtime: "server";
20
21
  instance: string;
21
22
  accessToken: string;
23
+ cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined;
22
24
  }, {
23
25
  runtime: "server";
24
26
  instance: string;
25
27
  accessToken: string;
28
+ cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined;
26
29
  }>, z.ZodObject<{
27
30
  runtime: z.ZodLiteral<"browser">;
31
+ cache: z.ZodOptional<z.ZodEnum<["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]>>;
28
32
  }, "strip", z.ZodTypeAny, {
29
33
  runtime: "browser";
34
+ cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined;
30
35
  }, {
31
36
  runtime: "browser";
37
+ cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined;
32
38
  }>]>;
33
39
  /**
34
40
  * Type representing the validated client options.
package/dist/portal.d.ts CHANGED
@@ -15,20 +15,26 @@ declare const ClientOptionsSchema: z.ZodDiscriminatedUnion<"runtime", [z.ZodObje
15
15
  instance: z.ZodUnion<[z.ZodString, z.ZodString]>;
16
16
  runtime: z.ZodLiteral<"server">;
17
17
  accessToken: z.ZodString;
18
+ cache: z.ZodOptional<z.ZodEnum<["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]>>;
18
19
  }, "strip", z.ZodTypeAny, {
19
20
  runtime: "server";
20
21
  instance: string;
21
22
  accessToken: string;
23
+ cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined;
22
24
  }, {
23
25
  runtime: "server";
24
26
  instance: string;
25
27
  accessToken: string;
28
+ cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined;
26
29
  }>, z.ZodObject<{
27
30
  runtime: z.ZodLiteral<"browser">;
31
+ cache: z.ZodOptional<z.ZodEnum<["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]>>;
28
32
  }, "strip", z.ZodTypeAny, {
29
33
  runtime: "browser";
34
+ cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined;
30
35
  }, {
31
36
  runtime: "browser";
37
+ cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined;
32
38
  }>]>;
33
39
  /**
34
40
  * Type representing the validated client options.
package/dist/portal.mjs CHANGED
@@ -9,10 +9,12 @@ var ClientOptionsSchema = z.discriminatedUnion("runtime", [
9
9
  z.object({
10
10
  instance: UrlOrPathSchema,
11
11
  runtime: z.literal("server"),
12
- accessToken: ApplicationAccessTokenSchema
12
+ accessToken: ApplicationAccessTokenSchema,
13
+ cache: z.enum(["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]).optional()
13
14
  }),
14
15
  z.object({
15
- runtime: z.literal("browser")
16
+ runtime: z.literal("browser"),
17
+ cache: z.enum(["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]).optional()
16
18
  })
17
19
  ]);
18
20
  function getFullUrl(options) {
@@ -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 * // 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":[]}
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 cache: z.enum([\"default\", \"force-cache\", \"no-cache\", \"no-store\", \"only-if-cached\", \"reload\"]).optional(),\n }),\n z.object({\n runtime: z.literal(\"browser\"),\n cache: z.enum([\"default\", \"force-cache\", \"no-cache\", \"no-store\", \"only-if-cached\", \"reload\"]).optional(),\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;AAgIlB,SAAS,oBAAoB;AArHtB,IAAM,sBAAsB,EAAE,mBAAmB,WAAW;AAAA,EACjE,EAAE,OAAO;AAAA,IACP,UAAU;AAAA,IACV,SAAS,EAAE,QAAQ,QAAQ;AAAA,IAC3B,aAAa;AAAA,IACb,OAAO,EAAE,KAAK,CAAC,WAAW,eAAe,YAAY,YAAY,kBAAkB,QAAQ,CAAC,EAAE,SAAS;AAAA,EACzG,CAAC;AAAA,EACD,EAAE,OAAO;AAAA,IACP,SAAS,EAAE,QAAQ,SAAS;AAAA,IAC5B,OAAO,EAAE,KAAK,CAAC,WAAW,eAAe,YAAY,YAAY,kBAAkB,QAAQ,CAAC,EAAE,SAAS;AAAA,EACzG,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.12",
4
+ "version": "1.1.14-main4e68a067",
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.12",
55
+ "@settlemint/sdk-utils": "1.1.14-main4e68a067",
56
56
  "graphql-request": "^7",
57
57
  "zod": "^3"
58
58
  },