@ethlete/query 5.33.2 → 5.34.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @ethlete/query
2
2
 
3
+ ## 5.34.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`2cf5165`](https://github.com/ethlete-io/ethdk/commit/2cf5165074956da6ce918ac9a7b0585897744651) Thanks [@TomTomB](https://github.com/TomTomB)! - Add bearerDecryptFn to query 3 bearer auth provider config
8
+
9
+ ## 5.33.3
10
+
11
+ ### Patch Changes
12
+
13
+ - [`c4f21f5`](https://github.com/ethlete-io/ethdk/commit/c4f21f5e69a6379d19989bc15ddfd86ca7eacdbd) Thanks [@TomTomB](https://github.com/TomTomB)! - Fix gql query param parsing
14
+
3
15
  ## 5.33.2
4
16
 
5
17
  ### Patch Changes
@@ -122,7 +122,10 @@ const buildQueryString = (params, config) => {
122
122
  const ignoredValuesFns = config?.ignoredValuesFns ?? [isNaN$1, isEmptyString];
123
123
  const queryParams = [];
124
124
  function processValue(key, value) {
125
- if (config?.useJsonStringify) {
125
+ if (config?.objectNotation === 'json-stringify') {
126
+ if (value === undefined) {
127
+ return false;
128
+ }
126
129
  if (ignoredValues.includes(value)) {
127
130
  return false;
128
131
  }
@@ -130,7 +133,8 @@ const buildQueryString = (params, config) => {
130
133
  return false;
131
134
  }
132
135
  const encodedKey = encodeURIComponent(key);
133
- const encodedValue = encodeURIComponent(JSON.stringify(value));
136
+ const val = typeof value === 'object' ? JSON.stringify(value) : value;
137
+ const encodedValue = encodeURIComponent(val);
134
138
  queryParams.push(`${encodedKey}=${encodedValue}`);
135
139
  return true;
136
140
  }
@@ -716,19 +720,12 @@ class QueryCreator {
716
720
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
717
721
  // @ts-ignore
718
722
  this.prepare = (args) => {
719
- const shouldUseJsonStringifyForQs = isGqlQueryConfig(this._queryConfig) &&
720
- (this._queryConfig.transferVia === 'GET' ||
721
- (this._client.config.request?.gql?.transferVia === 'GET' && !this._queryConfig.transferVia));
722
- const originalQueryParams = this._client.config.request?.queryParams;
723
- const queryParamConfig = originalQueryParams
724
- ? { ...originalQueryParams, useJsonStringify: shouldUseJsonStringifyForQs }
725
- : undefined;
726
723
  const route = buildRoute({
727
724
  base: this._client.config.baseRoute,
728
725
  route: this._queryConfig.route,
729
726
  pathParams: args?.pathParams,
730
727
  queryParams: computeQueryQueryParams({ config: this._queryConfig, client: this._client, args }),
731
- queryParamConfig,
728
+ queryParamConfig: this._client.config.request?.queryParams,
732
729
  });
733
730
  const cacheKey = (args?.config?.queryStoreCacheKey ?? '') + buildQueryCacheKey$1(route, args);
734
731
  if (shouldCacheQuery$1(this._queryConfig.method) && !args?.config?.skipQueryStore) {
@@ -1007,17 +1004,19 @@ const getOpName = /(query|mutation) ?([\w\d-_]+)? ?\(.*?\)? \{/;
1007
1004
  const transformGql = (str) => {
1008
1005
  str = Array.isArray(str) ? str.join('') : str;
1009
1006
  const name = getOpName.exec(str);
1010
- return function (variables) {
1007
+ return (variables) => {
1011
1008
  const data = { query: str };
1012
1009
  if (variables)
1013
- data['variables'] = variables;
1010
+ data['variables'] = JSON.stringify(variables);
1014
1011
  if (name && name.length) {
1015
1012
  const operationName = name[2];
1016
1013
  if (operationName)
1017
1014
  data['operationName'] = name[2];
1018
1015
  }
1019
- // minify the query
1020
- data.query = data.query.replace(/\s+/g, ' ').trim();
1016
+ if (!isDevMode()) {
1017
+ // minify the query
1018
+ data.query = data.query.replace(/\s+/g, ' ').trim();
1019
+ }
1021
1020
  return data;
1022
1021
  };
1023
1022
  };
@@ -3003,6 +3002,12 @@ const createBearerAuthProvider = (options) => {
3003
3002
  const query = latestExecutedQuery();
3004
3003
  return query?.query?.tokens()?.tokens ?? null;
3005
3004
  });
3005
+ const bearerData = computed(() => {
3006
+ const accessToken = tokens()?.accessToken;
3007
+ if (!accessToken)
3008
+ return null;
3009
+ return (options.bearerDecryptFn?.(accessToken) ?? decryptBearer(accessToken));
3010
+ });
3006
3011
  toObservable(computed(() => {
3007
3012
  const query = latestExecutedQuery();
3008
3013
  const expiresIn = query?.query?.expiresIn() ?? null;
@@ -3150,6 +3155,7 @@ const createBearerAuthProvider = (options) => {
3150
3155
  tryLoginWithCookie,
3151
3156
  latestExecutedQuery: latestNonInternalQuery.asReadonly(),
3152
3157
  tokens,
3158
+ bearerData,
3153
3159
  };
3154
3160
  if (cookieEnabled()) {
3155
3161
  if (!cookieOptions.autoLoginExcludeRoutes.some((r) => route().startsWith(r))) {
@@ -3179,6 +3185,7 @@ const createBearerAuthProviderConfig = (options) => {
3179
3185
  selectRole: options.selectRole,
3180
3186
  tokenLogin: options.tokenLogin,
3181
3187
  tokenRefresh: options.tokenRefresh,
3188
+ bearerDecryptFn: options.bearerDecryptFn,
3182
3189
  };
3183
3190
  return bearerAuthProviderConfig;
3184
3191
  };
@@ -4338,9 +4345,7 @@ const createQueryRepository = (config) => {
4338
4345
  route: options.route,
4339
4346
  pathParams: args?.pathParams,
4340
4347
  queryParams: args?.queryParams,
4341
- queryParamConfig: options.internalRunQueryOptions?.forceJsonStringifyInQueryParams
4342
- ? { useJsonStringify: true }
4343
- : config.queryString,
4348
+ queryParamConfig: config.queryString,
4344
4349
  });
4345
4350
  const key = shouldCache &&
4346
4351
  buildQueryCacheKey(`${options.key ? options.key + '_' : ''}${route}`, {
@@ -4694,7 +4699,6 @@ const createGqlExecuteFn = (executeOptions) => {
4694
4699
  options,
4695
4700
  internalOptions: {
4696
4701
  useQueryRepositoryCache: executeOptions.creatorInternals.method === 'QUERY',
4697
- forceJsonStringifyInQueryParams: executeOptions.creatorInternals.method === 'QUERY',
4698
4702
  },
4699
4703
  transformResponse: (originalResponse) => {
4700
4704
  if (originalResponse && 'data' in originalResponse) {