@ethlete/query 5.16.0 → 5.16.2

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.
Files changed (184) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/esm2022/ethlete-query.mjs +5 -0
  3. package/esm2022/index.mjs +20 -0
  4. package/esm2022/lib/auth/auth-provider.types.mjs +2 -0
  5. package/esm2022/lib/auth/auth-provider.utils.mjs +25 -0
  6. package/esm2022/lib/auth/basic-auth-provider.mjs +15 -0
  7. package/esm2022/lib/auth/bearer-auth-provider.mjs +168 -0
  8. package/esm2022/lib/auth/custom-header-auth-provider.mjs +12 -0
  9. package/esm2022/lib/auth/index.mjs +6 -0
  10. package/esm2022/lib/class-validator/class-validator.types.mjs +2 -0
  11. package/esm2022/lib/class-validator/class-validator.utils.mjs +4 -0
  12. package/esm2022/lib/class-validator/index.mjs +3 -0
  13. package/esm2022/lib/devtools/components/query-devtools/index.mjs +2 -0
  14. package/esm2022/lib/devtools/components/query-devtools/query-devtools.component.mjs +297 -0
  15. package/esm2022/lib/devtools/pipes/index.mjs +2 -0
  16. package/esm2022/lib/devtools/pipes/query-short-name.pipe.mjs +24 -0
  17. package/esm2022/lib/devtools/utils/index.mjs +2 -0
  18. package/esm2022/lib/devtools/utils/query-client.utils.mjs +13 -0
  19. package/esm2022/lib/directives/index.mjs +4 -0
  20. package/esm2022/lib/directives/infinity-query-trigger.directive.mjs +56 -0
  21. package/esm2022/lib/directives/infinity-query.directive.mjs +147 -0
  22. package/esm2022/lib/directives/query.directive.mjs +123 -0
  23. package/esm2022/lib/entity/entity-store.mjs +127 -0
  24. package/esm2022/lib/entity/entity.types.mjs +2 -0
  25. package/esm2022/lib/entity/entity.utils.mjs +29 -0
  26. package/esm2022/lib/entity/index.mjs +4 -0
  27. package/esm2022/lib/gql/gql.mjs +23 -0
  28. package/esm2022/lib/gql/index.mjs +2 -0
  29. package/esm2022/lib/infinite-query/index.mjs +4 -0
  30. package/esm2022/lib/infinite-query/infinity-query.mjs +171 -0
  31. package/esm2022/lib/infinite-query/infinity-query.types.mjs +2 -0
  32. package/esm2022/lib/infinite-query/infinity-query.utils.mjs +3 -0
  33. package/esm2022/lib/logger/index.mjs +2 -0
  34. package/esm2022/lib/logger/logger.mjs +16 -0
  35. package/esm2022/lib/query/index.mjs +4 -0
  36. package/esm2022/lib/query/query.mjs +430 -0
  37. package/esm2022/lib/query/query.types.mjs +2 -0
  38. package/esm2022/lib/query/query.utils.mjs +253 -0
  39. package/esm2022/lib/query-client/index.mjs +4 -0
  40. package/esm2022/lib/query-client/query-client.mjs +80 -0
  41. package/esm2022/lib/query-client/query-client.types.mjs +2 -0
  42. package/esm2022/lib/query-client/query-client.utils.mjs +20 -0
  43. package/esm2022/lib/query-creator/index.mjs +3 -0
  44. package/esm2022/lib/query-creator/query-creator.mjs +55 -0
  45. package/esm2022/lib/query-creator/query-creator.types.mjs +2 -0
  46. package/esm2022/lib/query-form/index.mjs +4 -0
  47. package/esm2022/lib/query-form/query-form.mjs +379 -0
  48. package/esm2022/lib/query-form/query-form.types.mjs +2 -0
  49. package/esm2022/lib/query-form/query-form.utils.mjs +97 -0
  50. package/esm2022/lib/query-store/index.mjs +2 -0
  51. package/esm2022/lib/query-store/query-store.mjs +144 -0
  52. package/esm2022/lib/request/index.mjs +4 -0
  53. package/esm2022/lib/request/request.mjs +196 -0
  54. package/esm2022/lib/request/request.types.mjs +2 -0
  55. package/esm2022/lib/request/request.util.mjs +252 -0
  56. package/esm2022/lib/symfony/index.mjs +3 -0
  57. package/esm2022/lib/symfony/symfony.types.mjs +2 -0
  58. package/esm2022/lib/symfony/symfony.utils.mjs +31 -0
  59. package/esm2022/lib/utils/data.utils.mjs +138 -0
  60. package/esm2022/lib/utils/deep-freeze.util.mjs +17 -0
  61. package/esm2022/lib/utils/def.util.mjs +8 -0
  62. package/esm2022/lib/utils/index.mjs +4 -0
  63. package/fesm2022/ethlete-query.mjs +3289 -0
  64. package/fesm2022/ethlete-query.mjs.map +1 -0
  65. package/{src/index.ts → index.d.ts} +0 -2
  66. package/lib/auth/auth-provider.types.d.ts +133 -0
  67. package/lib/auth/auth-provider.utils.d.ts +9 -0
  68. package/lib/auth/basic-auth-provider.d.ts +10 -0
  69. package/lib/auth/bearer-auth-provider.d.ts +23 -0
  70. package/lib/auth/custom-header-auth-provider.d.ts +9 -0
  71. package/{src/lib/class-validator/class-validator.types.ts → lib/class-validator/class-validator.types.d.ts} +3 -4
  72. package/lib/class-validator/class-validator.utils.d.ts +2 -0
  73. package/lib/devtools/components/query-devtools/query-devtools.component.d.ts +151 -0
  74. package/lib/devtools/pipes/query-short-name.pipe.d.ts +8 -0
  75. package/lib/devtools/utils/query-client.utils.d.ts +12 -0
  76. package/lib/directives/infinity-query-trigger.directive.d.ts +15 -0
  77. package/lib/directives/infinity-query.directive.d.ts +49 -0
  78. package/lib/directives/query.directive.d.ts +63 -0
  79. package/lib/entity/entity-store.d.ts +25 -0
  80. package/lib/entity/entity.types.d.ts +25 -0
  81. package/lib/entity/entity.utils.d.ts +12 -0
  82. package/lib/gql/gql.d.ts +6 -0
  83. package/lib/infinite-query/infinity-query.d.ts +29 -0
  84. package/lib/infinite-query/infinity-query.types.d.ts +104 -0
  85. package/lib/infinite-query/infinity-query.utils.d.ts +4 -0
  86. package/lib/logger/logger.d.ts +12 -0
  87. package/lib/query/query.d.ts +60 -0
  88. package/lib/query/query.types.d.ts +388 -0
  89. package/lib/query/query.utils.d.ts +82 -0
  90. package/lib/query-client/query-client.d.ts +29 -0
  91. package/lib/query-client/query-client.types.d.ts +82 -0
  92. package/lib/query-client/query-client.utils.d.ts +4 -0
  93. package/lib/query-creator/query-creator.d.ts +20 -0
  94. package/lib/query-creator/query-creator.types.d.ts +13 -0
  95. package/lib/query-form/query-form.d.ts +91 -0
  96. package/lib/query-form/query-form.types.d.ts +145 -0
  97. package/lib/query-form/query-form.utils.d.ts +13 -0
  98. package/lib/query-store/query-store.d.ts +31 -0
  99. package/lib/request/request.d.ts +3 -0
  100. package/lib/request/request.types.d.ts +126 -0
  101. package/lib/request/request.util.d.ts +92 -0
  102. package/lib/symfony/symfony.types.d.ts +19 -0
  103. package/lib/symfony/symfony.utils.d.ts +6 -0
  104. package/lib/utils/data.utils.d.ts +59 -0
  105. package/lib/utils/deep-freeze.util.d.ts +1 -0
  106. package/{src/lib/utils/def.util.ts → lib/utils/def.util.d.ts} +1 -1
  107. package/package.json +23 -6
  108. package/.eslintrc.json +0 -40
  109. package/jest.config.ts +0 -23
  110. package/ng-package.json +0 -8
  111. package/project.json +0 -37
  112. package/src/lib/auth/auth-provider.types.ts +0 -160
  113. package/src/lib/auth/auth-provider.utils.ts +0 -39
  114. package/src/lib/auth/basic-auth-provider.ts +0 -17
  115. package/src/lib/auth/bearer-auth-provider.ts +0 -243
  116. package/src/lib/auth/custom-header-auth-provider.ts +0 -13
  117. package/src/lib/class-validator/class-validator.utils.ts +0 -5
  118. package/src/lib/devtools/components/query-devtools/query-devtools.component.html +0 -402
  119. package/src/lib/devtools/components/query-devtools/query-devtools.component.scss +0 -360
  120. package/src/lib/devtools/components/query-devtools/query-devtools.component.ts +0 -427
  121. package/src/lib/devtools/pipes/query-short-name.pipe.ts +0 -24
  122. package/src/lib/devtools/utils/query-client.utils.ts +0 -25
  123. package/src/lib/directives/infinity-query-trigger.directive.ts +0 -58
  124. package/src/lib/directives/infinity-query.directive.ts +0 -208
  125. package/src/lib/directives/query.directive.ts +0 -201
  126. package/src/lib/entity/entity-store.ts +0 -180
  127. package/src/lib/entity/entity.types.ts +0 -34
  128. package/src/lib/entity/entity.utils.ts +0 -51
  129. package/src/lib/gql/gql.ts +0 -22
  130. package/src/lib/infinite-query/infinity-query.ts +0 -245
  131. package/src/lib/infinite-query/infinity-query.types.ts +0 -149
  132. package/src/lib/infinite-query/infinity-query.utils.ts +0 -14
  133. package/src/lib/logger/logger.ts +0 -30
  134. package/src/lib/query/query.ts +0 -631
  135. package/src/lib/query/query.types.ts +0 -532
  136. package/src/lib/query/query.utils.spec.ts +0 -92
  137. package/src/lib/query/query.utils.ts +0 -450
  138. package/src/lib/query-client/query-client.spec.ts +0 -77
  139. package/src/lib/query-client/query-client.ts +0 -195
  140. package/src/lib/query-client/query-client.types.ts +0 -101
  141. package/src/lib/query-client/query-client.utils.spec.ts +0 -61
  142. package/src/lib/query-client/query-client.utils.ts +0 -28
  143. package/src/lib/query-creator/query-creator.ts +0 -103
  144. package/src/lib/query-creator/query-creator.types.ts +0 -74
  145. package/src/lib/query-form/query-form.ts +0 -526
  146. package/src/lib/query-form/query-form.types.ts +0 -169
  147. package/src/lib/query-form/query-form.utils.ts +0 -116
  148. package/src/lib/query-store/query-store.ts +0 -192
  149. package/src/lib/request/request.ts +0 -253
  150. package/src/lib/request/request.types.ts +0 -164
  151. package/src/lib/request/request.util.spec.ts +0 -177
  152. package/src/lib/request/request.util.ts +0 -399
  153. package/src/lib/stories/angular-example-page.mdx +0 -85
  154. package/src/lib/stories/authentication-page.mdx +0 -35
  155. package/src/lib/stories/changelog-page.mdx +0 -9
  156. package/src/lib/stories/client-page.mdx +0 -100
  157. package/src/lib/stories/queries-page.mdx +0 -117
  158. package/src/lib/symfony/symfony.types.ts +0 -21
  159. package/src/lib/symfony/symfony.utils.ts +0 -43
  160. package/src/lib/utils/data.utils.ts +0 -280
  161. package/src/lib/utils/deep-freeze.util.ts +0 -21
  162. package/src/test-setup.ts +0 -1
  163. package/tsconfig.json +0 -29
  164. package/tsconfig.lib.json +0 -12
  165. package/tsconfig.lib.prod.json +0 -10
  166. package/tsconfig.spec.json +0 -11
  167. /package/{src/lib/auth/index.ts → lib/auth/index.d.ts} +0 -0
  168. /package/{src/lib/class-validator/index.ts → lib/class-validator/index.d.ts} +0 -0
  169. /package/{src/lib/devtools/components/query-devtools/index.ts → lib/devtools/components/query-devtools/index.d.ts} +0 -0
  170. /package/{src/lib/devtools/pipes/index.ts → lib/devtools/pipes/index.d.ts} +0 -0
  171. /package/{src/lib/devtools/utils/index.ts → lib/devtools/utils/index.d.ts} +0 -0
  172. /package/{src/lib/directives/index.ts → lib/directives/index.d.ts} +0 -0
  173. /package/{src/lib/entity/index.ts → lib/entity/index.d.ts} +0 -0
  174. /package/{src/lib/gql/index.ts → lib/gql/index.d.ts} +0 -0
  175. /package/{src/lib/infinite-query/index.ts → lib/infinite-query/index.d.ts} +0 -0
  176. /package/{src/lib/logger/index.ts → lib/logger/index.d.ts} +0 -0
  177. /package/{src/lib/query/index.ts → lib/query/index.d.ts} +0 -0
  178. /package/{src/lib/query-client/index.ts → lib/query-client/index.d.ts} +0 -0
  179. /package/{src/lib/query-creator/index.ts → lib/query-creator/index.d.ts} +0 -0
  180. /package/{src/lib/query-form/index.ts → lib/query-form/index.d.ts} +0 -0
  181. /package/{src/lib/query-store/index.ts → lib/query-store/index.d.ts} +0 -0
  182. /package/{src/lib/request/index.ts → lib/request/index.d.ts} +0 -0
  183. /package/{src/lib/symfony/index.ts → lib/symfony/index.d.ts} +0 -0
  184. /package/{src/lib/utils/index.ts → lib/utils/index.d.ts} +0 -0
@@ -0,0 +1,19 @@
1
+ import { HttpStatusCode } from '../request';
2
+ export interface SymfonyErrorTrace {
3
+ args: string[];
4
+ class: string;
5
+ file: string;
6
+ function: string;
7
+ line: number;
8
+ namespace: string;
9
+ short_class: string;
10
+ type: string;
11
+ }
12
+ export interface SymfonyError {
13
+ class: string;
14
+ detail: string;
15
+ status: HttpStatusCode;
16
+ title: string;
17
+ trace: SymfonyErrorTrace[];
18
+ type: string;
19
+ }
@@ -0,0 +1,6 @@
1
+ import { FormViolationListView, FormViolationView } from '@ethlete/types';
2
+ import { SymfonyError } from './symfony.types';
3
+ export declare const isSymfonyError: (error: unknown) => error is SymfonyError;
4
+ export declare const isSymfonyPagerfantaOutOfRangeError: (error: unknown) => error is SymfonyError;
5
+ export declare const isSymfonyFormViolationListError: (error: unknown) => error is FormViolationListView;
6
+ export declare const isSymfonyListError: (error: unknown) => error is FormViolationView[];
@@ -0,0 +1,59 @@
1
+ import { CreateComputedOptions, Signal } from '@angular/core';
2
+ import { ToObservableOptions, ToSignalOptions } from '@angular/core/rxjs-interop';
3
+ import { Observable, Subscribable } from 'rxjs';
4
+ import { AnyQuery, AnyQueryCollection, QueryOf, QueryState } from '../query';
5
+ import { QueryDataOf } from '../query-creator';
6
+ export interface QueryContainerConfig {
7
+ /**
8
+ * If `true`, the previous query will be aborted when a new query is pushed into the container.
9
+ * @default true // Only if the request can be cached (GET, OPTIONS, HEAD and GQL_QUERY). Otherwise false.
10
+ */
11
+ abortPrevious?: boolean;
12
+ /**
13
+ * If `true`, the query will be aborted when the container is destroyed.
14
+ * @default true // Only if the request can be cached (GET, OPTIONS, HEAD and GQL_QUERY). Otherwise false.
15
+ */
16
+ abortOnDestroy?: boolean;
17
+ /**
18
+ * If `true`, the previous polling will be stopped when a new query is pushed into the container.
19
+ * @default true // Only if the query has no other dependents and the request can be cached (GET, OPTIONS, HEAD and GQL_QUERY). Otherwise false.
20
+ */
21
+ stopPreviousPolling?: boolean;
22
+ }
23
+ export interface QueryFilterConfig {
24
+ /**
25
+ * If `true`, the response will be cached until the next response is received or the query fails.
26
+ * @default false
27
+ */
28
+ cacheResponse?: boolean;
29
+ }
30
+ export declare const addQueryContainerHandling: (obs: Observable<AnyQuery | AnyQuery[] | null>, valueFn: () => AnyQuery | AnyQuery[] | null | undefined, config?: QueryContainerConfig) => void;
31
+ export declare function toQuerySignal<T extends AnyQuery | null>(source: Observable<T> | Subscribable<T>): Signal<T | undefined>;
32
+ export declare function toQuerySignal<T extends AnyQuery | null>(source: Observable<T> | Subscribable<T>, options: NoInfer<ToSignalOptions<T | undefined>> & {
33
+ initialValue?: undefined;
34
+ requireSync?: false;
35
+ } & QueryContainerConfig): Signal<T | undefined>;
36
+ export declare function toQuerySignal<T extends AnyQuery | null>(source: Observable<T> | Subscribable<T>, options: NoInfer<ToSignalOptions<T | null>> & {
37
+ initialValue?: null;
38
+ requireSync?: false;
39
+ } & QueryContainerConfig): Signal<T | null>;
40
+ export declare function toQuerySignal<T extends AnyQuery | null>(source: Observable<T> | Subscribable<T>, options: NoInfer<ToSignalOptions<T>> & {
41
+ initialValue?: undefined;
42
+ requireSync: true;
43
+ } & QueryContainerConfig): Signal<T>;
44
+ export declare function toQuerySignal<T extends AnyQuery | null, const U extends T>(source: Observable<T> | Subscribable<T>, options: NoInfer<ToSignalOptions<T | U>> & {
45
+ initialValue: U;
46
+ requireSync?: false;
47
+ } & QueryContainerConfig): Signal<T | U>;
48
+ export declare function queryComputed<T extends AnyQuery | null>(computation: () => T, options?: CreateComputedOptions<T> & QueryContainerConfig & ToObservableOptions): Signal<T>;
49
+ /**
50
+ * Creates a signal that will only be reactive until the first query is created.
51
+ * All subsequent changes inside the computation will be ignored.
52
+ */
53
+ export declare function queryComputedTillTruthy<T extends AnyQuery | null>(computation: () => T, options?: CreateComputedOptions<T> & QueryContainerConfig & ToObservableOptions): Signal<T | null>;
54
+ export declare function queryArrayComputed<T extends AnyQuery[] | null>(computation: () => T, options?: CreateComputedOptions<T> & QueryContainerConfig & ToObservableOptions): Signal<T>;
55
+ export declare function toQuerySubject<T extends AnyQuery | null>(source: Signal<T>, options?: ToObservableOptions & QueryContainerConfig): Observable<T>;
56
+ export declare function queryStateSignal<T extends Signal<AnyQuery | AnyQueryCollection | null>>(source: T, options?: QueryFilterConfig): Signal<QueryState<QueryDataOf<QueryOf<ReturnType<T>>>> | null>;
57
+ export declare function queryStateResponseSignal<T extends Signal<AnyQuery | AnyQueryCollection | null>>(source: T, options?: QueryFilterConfig): Signal<QueryDataOf<QueryOf<ReturnType<T>>> | null>;
58
+ export declare function queryStateErrorSignal<T extends Signal<AnyQuery | AnyQueryCollection | null>>(source: T): Signal<import("@ethlete/query").RequestError<unknown> | null>;
59
+ export declare function queryStateLoadingSignal<T extends Signal<AnyQuery | AnyQueryCollection | null>>(source: T): Signal<import("../query").Loading | null>;
@@ -0,0 +1 @@
1
+ export declare const deepFreeze: <T extends Record<string, unknown>>(object: T) => T;
@@ -4,4 +4,4 @@
4
4
  * @see https://github.com/microsoft/TypeScript/issues/26242
5
5
  * @returns null
6
6
  */
7
- export const def = <Data>() => null as unknown as Data;
7
+ export declare const def: <Data>() => Data;
package/package.json CHANGED
@@ -1,13 +1,30 @@
1
1
  {
2
2
  "name": "@ethlete/query",
3
- "version": "5.16.0",
3
+ "version": "5.16.2",
4
4
  "peerDependencies": {
5
- "@angular/common": "18.0.6",
6
- "@angular/core": "18.0.6",
7
- "@angular/forms": "18.0.6",
8
- "@angular/router": "18.0.6",
5
+ "@angular/common": "^18.1.0",
6
+ "@angular/core": "^18.1.0",
7
+ "@angular/forms": "^18.1.0",
8
+ "@angular/router": "^18.1.0",
9
9
  "@ethlete/core": "^4.0.3",
10
10
  "@ethlete/types": "^1.6.2",
11
11
  "rxjs": "^7.8.1"
12
+ },
13
+ "module": "fesm2022/ethlete-query.mjs",
14
+ "typings": "index.d.ts",
15
+ "exports": {
16
+ "./package.json": {
17
+ "default": "./package.json"
18
+ },
19
+ ".": {
20
+ "types": "./index.d.ts",
21
+ "esm2022": "./esm2022/ethlete-query.mjs",
22
+ "esm": "./esm2022/ethlete-query.mjs",
23
+ "default": "./fesm2022/ethlete-query.mjs"
24
+ }
25
+ },
26
+ "sideEffects": false,
27
+ "dependencies": {
28
+ "tslib": "^2.3.0"
12
29
  }
13
- }
30
+ }
package/.eslintrc.json DELETED
@@ -1,40 +0,0 @@
1
- {
2
- "extends": ["../../.eslintrc.json"],
3
- "ignorePatterns": ["!**/*"],
4
- "overrides": [
5
- {
6
- "files": ["*.ts"],
7
- "extends": ["plugin:@nx/angular", "plugin:@angular-eslint/template/process-inline-templates"],
8
- "rules": {
9
- "@angular-eslint/directive-selector": [
10
- "error",
11
- {
12
- "type": "attribute",
13
- "prefix": "et"
14
- }
15
- ],
16
- "@angular-eslint/component-selector": [
17
- "error",
18
- {
19
- "type": ["element", "attribute"],
20
- "prefix": "et",
21
- "style": "kebab-case"
22
- }
23
- ],
24
- "@angular-eslint/no-host-metadata-property": "off"
25
- }
26
- },
27
- {
28
- "files": ["*.html"],
29
- "extends": ["plugin:@nx/angular-template"],
30
- "rules": {}
31
- },
32
- {
33
- "files": ["*.json"],
34
- "parser": "jsonc-eslint-parser",
35
- "rules": {
36
- "@nx/dependency-checks": "off"
37
- }
38
- }
39
- ]
40
- }
package/jest.config.ts DELETED
@@ -1,23 +0,0 @@
1
- /* eslint-disable */
2
- export default {
3
- displayName: 'query',
4
- preset: '../../jest.preset.js',
5
- setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
6
- globals: {},
7
- coverageDirectory: '../../coverage/libs/query',
8
- transform: {
9
- '^.+\\.(ts|mjs|js|html)$': [
10
- 'jest-preset-angular',
11
- {
12
- tsconfig: '<rootDir>/tsconfig.spec.json',
13
- stringifyContentPathRegex: '\\.(html|svg)$',
14
- },
15
- ],
16
- },
17
- transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
18
- snapshotSerializers: [
19
- 'jest-preset-angular/build/serializers/no-ng-attributes',
20
- 'jest-preset-angular/build/serializers/ng-snapshot',
21
- 'jest-preset-angular/build/serializers/html-comment',
22
- ],
23
- };
package/ng-package.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3
- "dest": "../../dist/libs/query",
4
- "assets": ["CHANGELOG.md"],
5
- "lib": {
6
- "entryFile": "src/index.ts"
7
- }
8
- }
package/project.json DELETED
@@ -1,37 +0,0 @@
1
- {
2
- "name": "query",
3
- "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
- "sourceRoot": "libs/query/src",
5
- "prefix": "et",
6
- "tags": [],
7
- "projectType": "library",
8
- "targets": {
9
- "build": {
10
- "executor": "@nx/angular:package",
11
- "outputs": ["{workspaceRoot}/dist/{projectRoot}"],
12
- "options": {
13
- "project": "libs/query/ng-package.json"
14
- },
15
- "configurations": {
16
- "production": {
17
- "tsConfig": "libs/query/tsconfig.lib.prod.json"
18
- },
19
- "development": {
20
- "tsConfig": "libs/query/tsconfig.lib.json"
21
- }
22
- },
23
- "defaultConfiguration": "production"
24
- },
25
- "test": {
26
- "executor": "@nx/jest:jest",
27
- "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
28
- "options": {
29
- "jestConfig": "libs/query/jest.config.ts"
30
- }
31
- },
32
- "lint": {
33
- "executor": "@nx/eslint:lint",
34
- "outputs": ["{options.outputFile}"]
35
- }
36
- }
37
- }
@@ -1,160 +0,0 @@
1
- import { AnyQueryCreator, QueryArgsOf, QueryResponseOf } from '../query-creator';
2
-
3
- export interface AuthProvider {
4
- /**
5
- * The up to date auth header.
6
- * This will automatically get injected into every query that has the `secure` property set to `true`.
7
- */
8
- header: Record<string, string>;
9
-
10
- /**
11
- * Cleanup function that gets called once the auth provider gets destroyed.
12
- * @internal
13
- */
14
- cleanUp(): void;
15
- }
16
-
17
- export interface AuthProviderBasicConfig {
18
- /**
19
- * Basic auth username
20
- */
21
- username: string;
22
-
23
- /**
24
- * Basic auth password
25
- */
26
- password: string;
27
- }
28
-
29
- export interface AuthProviderCustomHeaderConfig {
30
- /**
31
- * The custom header name
32
- * @example `X-Api-Key`
33
- */
34
- name: string;
35
-
36
- /**
37
- * The custom header value
38
- * @example `myApiKey`
39
- */
40
- value: string;
41
- }
42
-
43
- export interface AuthProviderBearerConfig<T extends AnyQueryCreator> {
44
- /**
45
- * The initial jwt
46
- */
47
- token?: string;
48
-
49
- /**
50
- * Refresh token configuration
51
- */
52
- refreshConfig?: BearerRefreshConfig<T>;
53
- }
54
-
55
- export interface BearerRefreshConfig<T extends AnyQueryCreator> {
56
- /**
57
- * The query used to trade the refresh token for a new token response.
58
- */
59
- queryCreator: T;
60
-
61
- /**
62
- * Determines if the token should be refreshed if **any** query returns a 401 response.
63
- * @default true
64
- */
65
- refreshOnUnauthorizedResponse?: boolean;
66
-
67
- /**
68
- * The initial refresh token
69
- */
70
- token?: string;
71
-
72
- /**
73
- * The cookie name where the refresh token is stored
74
- */
75
- cookieName?: string;
76
-
77
- /**
78
- * The domain of the cookie. If not set, the current origin will be used.
79
- *
80
- * @example
81
- * "https://example.com" -> "example.com"
82
- * "https://sub.example.com" -> "example.com"
83
- */
84
- cookieDomain?: string;
85
-
86
- /**
87
- * The days until the cookie expires
88
- * @default 30
89
- */
90
- cookieExpiresInDays?: number;
91
-
92
- /**
93
- * The path of the cookie
94
- * @default '/'
95
- */
96
- cookiePath?: string;
97
-
98
- /**
99
- * Enable or disable the cookie
100
- * @default true
101
- */
102
- cookieEnabled?: boolean;
103
-
104
- /**
105
- * The same site property of the cookie
106
- * @default 'lax'
107
- */
108
- cookieSameSite?: 'strict' | 'none' | 'lax';
109
-
110
- /**
111
- * The time in milliseconds before the token expires when the refresh should be triggered.
112
- * @default 300000 (5 minutes)
113
- */
114
- refreshBuffer?: number;
115
-
116
- /**
117
- * The expires in property name inside the jwt body
118
- * @default 'exp'
119
- */
120
- expiresInPropertyName?: string;
121
-
122
- /**
123
- * Determines when the token should be refreshed.
124
- * @default AuthBearerRefreshStrategy.BeforeExpiration
125
- */
126
- strategy?: AuthBearerRefreshStrategy;
127
-
128
- /**
129
- * Adapter function used to build the request body for the refresh request.
130
- * @default { body: { refreshToken: "refreshToken" } }
131
- */
132
- requestArgsAdapter?: (tokens: { token: string | null; refreshToken: string }) => QueryArgsOf<T>;
133
-
134
- /**
135
- * Adapter function used to extract the token and refreshToken from the response.
136
- * @default { token: "token", refreshToken: "refreshToken" }
137
- */
138
- responseAdapter?: (response: NonNullable<QueryResponseOf<T>>) => TokenResponse;
139
- }
140
-
141
- export const enum AuthBearerRefreshStrategy {
142
- /**
143
- * Automatically refresh the token 5 minutes before expiration.
144
- * The time can be configured with the `refreshBuffer` property.
145
- */
146
- BeforeExpiration = 'beforeExpiration',
147
- }
148
-
149
- export interface TokenResponse {
150
- /**
151
- * The access token used inside the authorization http header.
152
- */
153
- token: string | null;
154
-
155
- /**
156
- * The refresh token used for requesting a new token response once the current tokes is expired.
157
- * This property is required if the bearer refresh config is set.
158
- */
159
- refreshToken: string | null;
160
- }
@@ -1,39 +0,0 @@
1
- import { AnyQueryCreator } from '../query-creator';
2
- import { AuthProvider } from './auth-provider.types';
3
- import { BasicAuthProvider } from './basic-auth-provider';
4
- import { BearerAuthProvider } from './bearer-auth-provider';
5
- import { CustomHeaderAuthProvider } from './custom-header-auth-provider';
6
-
7
- export const isBasicAuthProvider = (authProvider: AuthProvider): authProvider is BasicAuthProvider =>
8
- authProvider instanceof BasicAuthProvider;
9
-
10
- export const isBearerAuthProvider = <T extends AnyQueryCreator>(
11
- authProvider: AuthProvider,
12
- ): authProvider is BearerAuthProvider<T> => authProvider instanceof BearerAuthProvider;
13
-
14
- export const isCustomHeaderAuthProvider = (authProvider: AuthProvider): authProvider is CustomHeaderAuthProvider =>
15
- authProvider instanceof CustomHeaderAuthProvider;
16
-
17
- export const decryptBearer = <Result = Record<string, unknown>>(token: string) => {
18
- try {
19
- const base64Url = token.split('.')[1];
20
-
21
- if (!base64Url) {
22
- return null;
23
- }
24
-
25
- const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
26
- const jsonPayload = decodeURIComponent(
27
- atob(base64)
28
- .split('')
29
- .map((c) => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2))
30
- .join(''),
31
- );
32
-
33
- return JSON.parse(jsonPayload) as Result;
34
- } catch (error) {
35
- console.error(`Invalid bearer token: ${token}`, error);
36
-
37
- return null;
38
- }
39
- };
@@ -1,17 +0,0 @@
1
- import { AuthProvider, AuthProviderBasicConfig } from './auth-provider.types';
2
-
3
- export class BasicAuthProvider implements AuthProvider {
4
- get header() {
5
- return { Authorization: `Basic ${this._basicAuthString}` };
6
- }
7
-
8
- private get _basicAuthString() {
9
- return btoa(`${this._config.username}:${this._config.password}`);
10
- }
11
-
12
- constructor(public _config: AuthProviderBasicConfig) {}
13
-
14
- cleanUp(): void {
15
- // noop
16
- }
17
- }