getta 0.4.7 → 1.0.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.
Files changed (104) hide show
  1. package/README.md +165 -7
  2. package/dist/main/index.mjs +621 -0
  3. package/dist/main/index.mjs.map +1 -0
  4. package/dist/tsconfig.build.tsbuildinfo +1 -0
  5. package/{lib → dist}/types/constants.d.ts +2 -2
  6. package/dist/types/constants.d.ts.map +1 -0
  7. package/dist/types/helpers/buildEndpoint/index.d.ts +3 -0
  8. package/dist/types/helpers/buildEndpoint/index.d.ts.map +1 -0
  9. package/{lib/types/helpers/build-endpoint → dist/types/helpers/buildEndpoint}/types.d.ts +2 -2
  10. package/dist/types/helpers/buildEndpoint/types.d.ts.map +1 -0
  11. package/dist/types/helpers/defaultPathTemplateCallback/index.d.ts +2 -0
  12. package/dist/types/helpers/defaultPathTemplateCallback/index.d.ts.map +1 -0
  13. package/dist/types/helpers/delay/index.d.ts +2 -0
  14. package/{lib → dist}/types/helpers/delay/index.d.ts.map +1 -1
  15. package/dist/types/helpers/getResponseGroup/index.d.ts +2 -0
  16. package/dist/types/helpers/getResponseGroup/index.d.ts.map +1 -0
  17. package/dist/types/helpers/isCacheabilityValid/index.d.ts +3 -0
  18. package/dist/types/helpers/isCacheabilityValid/index.d.ts.map +1 -0
  19. package/dist/types/index.d.ts +5 -0
  20. package/dist/types/index.d.ts.map +1 -0
  21. package/{lib → dist}/types/main.d.ts +12 -12
  22. package/dist/types/main.d.ts.map +1 -0
  23. package/dist/types/types.d.ts +161 -0
  24. package/dist/types/types.d.ts.map +1 -0
  25. package/package.json +113 -145
  26. package/src/{__tests__ → __testUtils__}/data/136-7317.json +1 -1
  27. package/src/{__tests__ → __testUtils__}/data/180-1387.json +1 -1
  28. package/src/{__tests__ → __testUtils__}/data/183-3905.json +1 -1
  29. package/src/{__tests__ → __testUtils__}/data/202-3315.json +1 -1
  30. package/src/__testUtils__/data/index.ts +23 -0
  31. package/src/__testUtils__/helpers/index.ts +49 -0
  32. package/src/constants.ts +28 -28
  33. package/src/helpers/buildEndpoint/index.ts +34 -0
  34. package/src/helpers/{build-endpoint → buildEndpoint}/types.ts +2 -2
  35. package/src/helpers/defaultPathTemplateCallback/index.test.ts +11 -0
  36. package/src/helpers/defaultPathTemplateCallback/index.ts +17 -0
  37. package/src/helpers/delay/index.ts +2 -2
  38. package/src/helpers/getResponseGroup/index.ts +25 -0
  39. package/src/helpers/isCacheabilityValid/index.ts +6 -0
  40. package/src/index.ts +4 -4
  41. package/src/main.test.ts +283 -411
  42. package/src/main.ts +238 -241
  43. package/src/types.ts +114 -16
  44. package/tsconfig.build.json +14 -0
  45. package/tsconfig.json +9 -0
  46. package/CHANGELOG.md +0 -250
  47. package/jest.setup.js +0 -10
  48. package/lib/browser/index.js +0 -2
  49. package/lib/browser/index.js.map +0 -1
  50. package/lib/browser/production.analysis.txt +0 -91
  51. package/lib/main/constants.js +0 -97
  52. package/lib/main/helpers/build-endpoint/index.js +0 -38
  53. package/lib/main/helpers/build-endpoint/types.js +0 -1
  54. package/lib/main/helpers/default-path-template-callback/index.js +0 -16
  55. package/lib/main/helpers/delay/index.js +0 -12
  56. package/lib/main/helpers/get-response-group/index.js +0 -27
  57. package/lib/main/helpers/is-cacheability-valid/index.js +0 -13
  58. package/lib/main/index.js +0 -62
  59. package/lib/main/main.js +0 -580
  60. package/lib/main/types.js +0 -1
  61. package/lib/module/constants.mjs +0 -49
  62. package/lib/module/helpers/build-endpoint/index.mjs +0 -28
  63. package/lib/module/helpers/build-endpoint/types.mjs +0 -0
  64. package/lib/module/helpers/default-path-template-callback/index.mjs +0 -9
  65. package/lib/module/helpers/delay/index.mjs +0 -4
  66. package/lib/module/helpers/get-response-group/index.mjs +0 -19
  67. package/lib/module/helpers/is-cacheability-valid/index.mjs +0 -6
  68. package/lib/module/index.mjs +0 -4
  69. package/lib/module/main.mjs +0 -576
  70. package/lib/module/types.mjs +0 -0
  71. package/lib/types/__tests__/data/index.d.ts +0 -17
  72. package/lib/types/__tests__/data/index.d.ts.map +0 -1
  73. package/lib/types/__tests__/helpers/index.d.ts +0 -29
  74. package/lib/types/__tests__/helpers/index.d.ts.map +0 -1
  75. package/lib/types/__tests__/types.d.ts +0 -13
  76. package/lib/types/__tests__/types.d.ts.map +0 -1
  77. package/lib/types/constants.d.ts.map +0 -1
  78. package/lib/types/helpers/build-endpoint/index.d.ts +0 -3
  79. package/lib/types/helpers/build-endpoint/index.d.ts.map +0 -1
  80. package/lib/types/helpers/build-endpoint/types.d.ts.map +0 -1
  81. package/lib/types/helpers/default-path-template-callback/index.d.ts +0 -3
  82. package/lib/types/helpers/default-path-template-callback/index.d.ts.map +0 -1
  83. package/lib/types/helpers/default-path-template-callback/index.test.d.ts +0 -2
  84. package/lib/types/helpers/default-path-template-callback/index.test.d.ts.map +0 -1
  85. package/lib/types/helpers/delay/index.d.ts +0 -2
  86. package/lib/types/helpers/get-response-group/index.d.ts +0 -2
  87. package/lib/types/helpers/get-response-group/index.d.ts.map +0 -1
  88. package/lib/types/helpers/is-cacheability-valid/index.d.ts +0 -3
  89. package/lib/types/helpers/is-cacheability-valid/index.d.ts.map +0 -1
  90. package/lib/types/index.d.ts +0 -5
  91. package/lib/types/index.d.ts.map +0 -1
  92. package/lib/types/main.d.ts.map +0 -1
  93. package/lib/types/main.test.d.ts +0 -2
  94. package/lib/types/main.test.d.ts.map +0 -1
  95. package/lib/types/types.d.ts +0 -69
  96. package/lib/types/types.d.ts.map +0 -1
  97. package/src/__tests__/data/index.ts +0 -19
  98. package/src/__tests__/helpers/index.ts +0 -61
  99. package/src/__tests__/types.ts +0 -14
  100. package/src/helpers/build-endpoint/index.ts +0 -34
  101. package/src/helpers/default-path-template-callback/index.test.ts +0 -11
  102. package/src/helpers/default-path-template-callback/index.ts +0 -16
  103. package/src/helpers/get-response-group/index.ts +0 -22
  104. package/src/helpers/is-cacheability-valid/index.ts +0 -6
package/src/types.ts CHANGED
@@ -1,38 +1,119 @@
1
- import Cachemap from "@cachemap/core";
2
- import { Func, PlainObject, StringObject } from "@repodog/types";
3
- import { Required } from "utility-types";
1
+ import { type Core } from '@cachemap/core';
2
+ import type { SetRequired } from 'type-fest';
4
3
 
5
- export type FetchMethod = "get" | "post" | "put" | "delete";
4
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
+ export type PlainObject = Record<string, any>;
6
6
 
7
- export type StreamReader = "arrayBuffer" | "blob" | "formData" | "json" | "text";
7
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
+ export type Func = (...args: any[]) => any;
9
+
10
+ export type FetchMethod = 'get' | 'post' | 'put' | 'delete';
11
+
12
+ export type StreamReader = 'arrayBuffer' | 'blob' | 'formData' | 'json' | 'text';
8
13
 
9
14
  export type ShortcutProperties<T extends string | number> = {
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
16
  [K in T]: <Resource = PlainObject>(...args: any[]) => Promise<FetchResponse<Resource>>;
11
17
  };
12
18
 
13
19
  export interface ConstructorOptions {
20
+ /**
21
+ * The base path of the url for all requests made from
22
+ * an instance of the rest client, i.e. https://www.example.com/api.
23
+ */
14
24
  basePath: string;
25
+ /**
26
+ * An optional callback to pass each response body through after
27
+ * it has been parsed by the stream reader.
28
+ */
15
29
  bodyParser?: Func;
16
- cache?: Cachemap;
30
+ /**
31
+ * An instance of the @cachemap/core cache for caching responses
32
+ * against the request. Caching is only enabled on GET requests.
33
+ * For more info on @cachemap/core see https://github.com/badbatch/cachemap.
34
+ */
35
+ cache?: Core;
36
+ /**
37
+ * Enables conditional requests with If-None-Match header.
38
+ * Default is true
39
+ */
17
40
  enableConditionalRequests?: boolean;
41
+ /**
42
+ * How long to wait for a request to respond before timing out
43
+ * and returning an error.
44
+ * Default is 5000
45
+ */
18
46
  fetchTimeout?: number;
19
- headers?: StringObject;
47
+ /**
48
+ * Any headers to attach to every request.
49
+ */
50
+ headers?: Record<string, string>;
51
+ /**
52
+ * Log function to pass rest client logs to a logger.
53
+ */
20
54
  log?: Log;
55
+ /**
56
+ * The maximum number of times a request can redirect before
57
+ * the rest client returns an error.
58
+ * Default is 5
59
+ */
21
60
  maxRedirects?: number;
61
+ /**
62
+ * The maximum number of times a request can retry before
63
+ * the rest client returns an error.
64
+ * Default is 3
65
+ */
22
66
  maxRetries?: number;
67
+ /**
68
+ * An optional path template regex that can be used to clean up
69
+ * the template url.
70
+ * Default is /({\w+\?})/g
71
+ */
23
72
  optionalPathTemplateRegExp?: RegExp;
73
+ /**
74
+ * A callback that takes the path template, the data to be injected into
75
+ * the template, and the path template regex, and returns the templated url.
76
+ * There is a default template callback that will cater to most needs.
77
+ */
24
78
  pathTemplateCallback?: PathTemplateCallback;
79
+ /**
80
+ * A regex to tell the rest client where to inject data into the
81
+ * template. There is a default one that will cater to most needs.
82
+ */
25
83
  pathTemplateRegExp?: RegExp;
84
+ /**
85
+ * The performance module to use for recording request
86
+ * durations.
87
+ */
26
88
  performance: Performance;
89
+ /**
90
+ * Any query params to attach to every request.
91
+ */
27
92
  queryParams?: PlainObject;
93
+ /**
94
+ * Whether to enable the rate limit feature.
95
+ */
96
+ rateLimit?: boolean;
97
+ /**
98
+ * How many requests per second to throttle the rest client.
99
+ * Default is 50
100
+ */
28
101
  rateLimitPerSecond?: number;
102
+ /**
103
+ * How many milliseconds to wait before retrying a request.
104
+ * Default is 100
105
+ */
29
106
  requestRetryWait?: number;
107
+ /**
108
+ * The stream reader to use when parsing the response body.
109
+ * Default is 'json'
110
+ */
30
111
  streamReader?: StreamReader;
31
112
  }
32
113
 
33
114
  export interface FetchOptions {
34
115
  body?: BodyInit;
35
- headers: StringObject;
116
+ headers: Record<string, string>;
36
117
  method: FetchMethod;
37
118
  redirects?: number;
38
119
  retries?: number;
@@ -46,17 +127,32 @@ export interface FetchRedirectHandlerOptions extends FetchOptions {
46
127
 
47
128
  export type Log = (message: string, data: PlainObject, logLevel?: LogLevel) => void;
48
129
 
49
- export type LogLevel = "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly";
130
+ export type LogLevel = 'error' | 'warn' | 'info' | 'http' | 'verbose' | 'debug' | 'silly';
50
131
 
51
132
  export interface Performance {
52
133
  now(): number;
53
134
  }
54
135
 
55
136
  export interface RequestOptions {
137
+ /**
138
+ * For POST and PUT methods, the body to send with the request.
139
+ */
56
140
  body?: BodyInit;
57
- headers?: StringObject;
141
+ /**
142
+ * Any headers to attach to the request.
143
+ */
144
+ headers?: Record<string, string>;
145
+ /**
146
+ * The fetch method.
147
+ */
58
148
  method?: FetchMethod;
59
- pathTemplateData?: StringObject;
149
+ /**
150
+ * Data to be injected into the path template.
151
+ */
152
+ pathTemplateData?: Record<string, string>;
153
+ /**
154
+ * Any query params to attach to the request.
155
+ */
60
156
  queryParams?: PlainObject;
61
157
  }
62
158
 
@@ -67,9 +163,9 @@ export interface ResponseDataWithErrors<Resource = PlainObject> {
67
163
  errors?: Error[];
68
164
  }
69
165
 
70
- export type PathTemplateCallback = (path: string, data: StringObject, pathTemplateRegExp: RegExp) => string;
166
+ export type PathTemplateCallback = (path: string, data: Record<string, string>, pathTemplateRegExp: RegExp) => string;
71
167
 
72
- export type PendingRequestResolver = (value: FetchResponse<PlainObject>) => void;
168
+ export type PendingRequestResolver = (value: FetchResponse) => void;
73
169
 
74
170
  export interface PendingRequestResolvers {
75
171
  resolve: PendingRequestResolver;
@@ -80,6 +176,8 @@ export interface RequestTracker {
80
176
  pending: Map<string, PendingRequestResolvers[]>;
81
177
  }
82
178
 
83
- export interface Shortcuts {
84
- [key: string]: [string, Required<RequestOptions, "method">];
85
- }
179
+ export type Shortcuts = Record<string, [string, SetRequired<RequestOptions, 'method'>]>;
180
+
181
+ export type Context = {
182
+ startTime?: number;
183
+ };
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "@repodog/ts-config/build.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist/types"
6
+ },
7
+ "include": [
8
+ "src/**/*"
9
+ ],
10
+ "exclude": [
11
+ "**/*.test.*",
12
+ "**/__testUtils__/**"
13
+ ]
14
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@repodog/ts-config/index.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src"
5
+ },
6
+ "include": [
7
+ "src/**/*"
8
+ ]
9
+ }
package/CHANGELOG.md DELETED
@@ -1,250 +0,0 @@
1
- #### 0.4.7 (2023-08-13)
2
-
3
- ##### Bug Fixes
4
-
5
- * output mjs files for module ([de027423](https://github.com/badbatch/getta/commit/de027423088da3a47346ef9c837f96481a04924b))
6
-
7
- #### 0.4.6 (2023-07-12)
8
-
9
- ##### Refactors
10
-
11
- * change lib default export to nameed ([389830fa](https://github.com/badbatch/getta/commit/389830faab370064f69b80a28b34fd2bcbe8cd52))
12
-
13
- #### 0.4.5 (2023-07-12)
14
-
15
- ##### Bug Fixes
16
-
17
- * move peers to deps ([317b60c4](https://github.com/badbatch/getta/commit/317b60c46ec2628e04e90c6343372a3a54069c0f))
18
-
19
- #### 0.4.4 (2022-11-16)
20
-
21
- ##### Bug Fixes
22
-
23
- * clear timeout timer when request added to rate limit queue ([51b6e0af](https://github.com/badbatch/getta/commit/51b6e0aff926a2e62cafc31a0d9f526daf05fff2))
24
-
25
- #### 0.4.3 (2022-11-15)
26
-
27
- ##### Bug Fixes
28
-
29
- * await promise to catch error ([201e04c7](https://github.com/badbatch/getta/commit/201e04c765cd447efbd8a54cb87f65c019d76bfb))
30
-
31
- #### 0.4.2 (2022-10-25)
32
-
33
- ##### Bug Fixes
34
-
35
- * context passing into shorthand methods ([56cb1c3c](https://github.com/badbatch/getta/commit/56cb1c3c01a38f29bb942720ca2d6a053abd25e5))
36
-
37
- #### 0.4.1 (2022-10-24)
38
-
39
- ##### Refactors
40
-
41
- * update logging ([addf14cc](https://github.com/badbatch/getta/commit/addf14cc344ed31aa409ea564cae15bb3f5d2b08))
42
-
43
- ### 0.4.0 (2022-10-23)
44
-
45
- ##### New Features
46
-
47
- * add logging ([2655d942](https://github.com/badbatch/getta/commit/2655d9429ce054e45998a080b3510a92c61240f9))
48
-
49
- ### 0.3.0 (2022-06-28)
50
-
51
- ##### New Features
52
-
53
- * add rate limiting ([f8275dd8](https://github.com/badbatch/getta/commit/f8275dd83608743bb587df9305cc85936678bced))
54
-
55
- #### 0.2.3 (2022-06-27)
56
-
57
- ##### Refactors
58
-
59
- * reorder code to make debugging easier ([3b3b89e7](https://github.com/badbatch/getta/commit/3b3b89e7177ff620a6dd35bb04d4b254d132c524))
60
-
61
- #### 0.2.2 (2022-06-24)
62
-
63
- ##### Bug Fixes
64
-
65
- * add second attempt to parse body when invalid json ([5a27b0ef](https://github.com/badbatch/getta/commit/5a27b0eff2855bec70d0d54cf75b8b53e71d076f))
66
-
67
- #### 0.2.1 (2022-06-06)
68
-
69
- ##### Bug Fixes
70
-
71
- * catch response parsing error correctly ([07871c37](https://github.com/badbatch/getta/commit/07871c37979bcd02933d4e610e18e8c68b06532f))
72
-
73
- ### 0.2.0 (2022-06-01)
74
-
75
- ##### New Features
76
-
77
- * enable method overriding on shortcut properties ([053c3556](https://github.com/badbatch/getta/commit/053c35567d717d6e56c9ae4ed46c73af622b1734))
78
-
79
- #### 0.1.22 (2022-04-01)
80
-
81
- ##### Chores
82
-
83
- * upgrade cachemap deps ([97864a27](https://github.com/badbatch/getta/commit/97864a2728961f4937a441c36188750508d466be))
84
-
85
- #### 0.1.21 (2022-01-21)
86
-
87
- ##### Chores
88
-
89
- * **deps:**
90
- * bump trim-off-newlines from 1.0.1 to 1.0.3 ([a0393578](https://github.com/badbatch/getta/commit/a0393578be20485d901bf0f5757dedda213718dd))
91
- * bump ws from 7.4.5 to 7.5.6 ([a305a8c9](https://github.com/badbatch/getta/commit/a305a8c9bfc6e5b3240d019f99e5fbb5025d5e90))
92
- * bump shelljs from 0.8.4 to 0.8.5 ([040c8a16](https://github.com/badbatch/getta/commit/040c8a164f4a8333a419cec6f6b6ab0048ab16e7))
93
- * bump tmpl from 1.0.4 to 1.0.5 ([aafc23ec](https://github.com/badbatch/getta/commit/aafc23ec2555e6b85f7e4813dd6f37090e746237))
94
- * bump semver-regex from 3.1.2 to 3.1.3 ([1ba20153](https://github.com/badbatch/getta/commit/1ba201531d39946909fc14ce5da201d65d86b0e3))
95
- * bump path-parse from 1.0.6 to 1.0.7 ([7b6ec209](https://github.com/badbatch/getta/commit/7b6ec209b3413563b88eb0174bca8e81126e6d4c))
96
- * bump underscore from 1.9.1 to 1.13.1 ([d150d17a](https://github.com/badbatch/getta/commit/d150d17a2842738d17a9fddf39153af33c48025d))
97
- * bump highlight.js from 9.18.1 to 9.18.5 ([314b8244](https://github.com/badbatch/getta/commit/314b824448a5a78c1a8b129d3e979d1b7fa1d5b4))
98
-
99
- ##### Bug Fixes
100
-
101
- * header key format when adding cache control ([7bd74d3f](https://github.com/badbatch/getta/commit/7bd74d3f964dd87a808f76ae7598bcc73ab9775c))
102
-
103
- #### 0.1.20 (2022-01-21)
104
-
105
- ##### Bug Fixes
106
-
107
- * return headers with cache control if match found in cache ([be4e6c9b](https://github.com/badbatch/getta/commit/be4e6c9be7b18f73f16533863cdfdfe75fd6feb6))
108
-
109
- #### 0.1.19 (2022-01-18)
110
-
111
- ##### Bug Fixes
112
-
113
- * remove ending forward slash on endpoint if it exists ([23f007cb](https://github.com/badbatch/getta/commit/23f007cb100b0ea209fc42476f07a162ea24e187))
114
-
115
- #### 0.1.17 (2021-12-27)
116
-
117
- ##### Chores
118
-
119
- * upgrade cachemap core package ([f36d5aa1](https://github.com/badbatch/getta/commit/f36d5aa1c08d725b1e36d839d7d284be436390c2))
120
-
121
- #### 0.1.16 (2021-12-22)
122
-
123
- ##### Bug Fixes
124
-
125
- * circular dependency ([301b5cfb](https://github.com/badbatch/getta/commit/301b5cfbdbaf8a29a8250b614c87a15ca831ebfb))
126
-
127
- #### 0.1.15 (2021-12-22)
128
-
129
- ##### Bug Fixes
130
-
131
- * add missing cachemap/controller dev dependency ([1de8279d](https://github.com/badbatch/getta/commit/1de8279d207fb7ed4e7ade01674624de181111d3))
132
-
133
- #### 0.1.14 (2021-12-22)
134
-
135
- ##### Chores
136
-
137
- * bump cachemap dependencies ([b6a07030](https://github.com/badbatch/getta/commit/b6a07030d64db83ac937cab853774175f4d797b7))
138
-
139
- #### 0.1.11 (2021-10-19)
140
-
141
- ##### Bug Fixes
142
-
143
- * update shorthand method signature ([7880912c](https://github.com/badbatch/getta/commit/7880912cbfc9083aa4f41d357a9bba6db7c4ccdf))
144
-
145
- #### 0.1.10 (2021-10-19)
146
-
147
- ##### New Features
148
-
149
- * pass resource type into shorthand method ([1922e959](https://github.com/badbatch/getta/commit/1922e9599389ab75c5d47ccbd761d8b4cdd9ec49))
150
-
151
- #### 0.1.9 (2021-10-19)
152
-
153
- ##### Bug Fixes
154
-
155
- * shortand return type is wrong ([7da27bf0](https://github.com/badbatch/getta/commit/7da27bf0e4207fdfe04f99bae9614bb9103c0c02))
156
-
157
- #### 0.1.8 (2021-10-19)
158
-
159
- ##### Bug Fixes
160
-
161
- * error in deploy script ([e75d9c93](https://github.com/badbatch/getta/commit/e75d9c932886a1a80881bf863145ec351338e0f1))
162
-
163
- #### 0.1.7 (2021-10-19)
164
-
165
- ##### Bug Fixes
166
-
167
- * get build working by removing codecov step ([27ab9b09](https://github.com/badbatch/getta/commit/27ab9b093c880397cb2e3bd4c4fc95a4dea9d507))
168
- * force correct return signature for shortcut methods ([f6551dc5](https://github.com/badbatch/getta/commit/f6551dc5416a5ba1b1011081b9ed1323ba9e0061))
169
-
170
- #### 0.1.6 (2021-05-20)
171
-
172
- ##### New Features
173
-
174
- * return entire response object with data and errors ([ee6a4213](https://github.com/badbatch/getta/commit/ee6a4213ef2ee3e953bf7897123d755541d48fdf))
175
-
176
- #### 0.1.5 (2020-03-03)
177
-
178
- ##### Chores
179
-
180
- * update dependencies and sort peer versions ([ec4d4b8d](https://github.com/badbatch/getta/commit/ec4d4b8d81c10a2c9e77cf32d1b66208ba28f68a))
181
-
182
- #### 0.1.4 (2020-03-02)
183
-
184
- ##### Bug Fixes
185
-
186
- * change order of query param logic in build endpoint ([f25ed4c9](https://github.com/badbatch/getta/commit/f25ed4c903c37713c02f511f13cf6de83a9ffb0c))
187
-
188
- #### 0.1.3 (2020-03-02)
189
-
190
- ##### Refactors
191
-
192
- * changing test folder name ([9cee1820](https://github.com/badbatch/getta/commit/9cee18200f4327648e2e3eb0a89c6af8f912db1c))
193
-
194
- #### 0.1.2 (2019-11-16)
195
-
196
- ##### Refactors
197
-
198
- * change constant to helper method ([9fb69dda](https://github.com/badbatch/getta/commit/9fb69dda8fcc51627450101c81132d6bbfe73d62))
199
-
200
- #### 0.1.1 (2019-11-15)
201
-
202
- ##### Chores
203
-
204
- * update dependencies, including cachemap ([fa6c8f65](https://github.com/badbatch/getta/commit/fa6c8f651007c2c01377bfc8aac0fa7821cd02cf))
205
-
206
- ##### Documentation Changes
207
-
208
- * update readme ([42bbfe1f](https://github.com/badbatch/getta/commit/42bbfe1f5eca6a45445715b3b69680dc14a17fca))
209
-
210
- ### 0.1.0 (2019-11-12)
211
-
212
- ##### Chores
213
-
214
- * add bootstrap files ([07be80ac](https://github.com/badbatch/getta/commit/07be80ac994fff9b918c4bde5ef230952d30bdd5))
215
-
216
- ##### Documentation Changes
217
-
218
- * fix links in readme ([20edde8f](https://github.com/badbatch/getta/commit/20edde8fd9e45dc2616e218a1af00c3db72b2434))
219
- * add readme and fix package json links ([8ca3b843](https://github.com/badbatch/getta/commit/8ca3b84388cc25b2bb0a94e9f5cbbc2e06706f64))
220
- * adding typedocs ([1c741a77](https://github.com/badbatch/getta/commit/1c741a7781ecc0348ac37699395cc533b16a8e76))
221
-
222
- ##### New Features
223
-
224
- * add shortcuts to createRestClient method ([9498a105](https://github.com/badbatch/getta/commit/9498a10543ef5f749e82b2eeb09152650253d3e7))
225
- * finishing rest client and starting unit tests ([9cbf0495](https://github.com/badbatch/getta/commit/9cbf04950955c930d22919df404840764a43f46f))
226
-
227
- ##### Bug Fixes
228
-
229
- * error in travis config ([5fa09646](https://github.com/badbatch/getta/commit/5fa09646c96e38b648e713af219e98ee48b1bf64))
230
- * allow shortcut property keys to be passed in ([509886a6](https://github.com/badbatch/getta/commit/509886a624b832f2bb0950414dc9a0ec3b89c8f6))
231
-
232
- ##### Other Changes
233
-
234
- * dylanaubrey/getta into wip ([e0f5886b](https://github.com/badbatch/getta/commit/e0f5886b70d59d7dae63cedb3146318b9fcd90ff))
235
-
236
- ##### Refactors
237
-
238
- * updating test structure ([13b91f75](https://github.com/badbatch/getta/commit/13b91f751dee71a18561db0f60d630edec2a1da9))
239
- * moving files over to typescript ([da29e421](https://github.com/badbatch/getta/commit/da29e421499df136f15481fedd308fc9481750ed))
240
-
241
- ##### Tests
242
-
243
- * finishing unit tests ([add5025f](https://github.com/badbatch/getta/commit/add5025f4362809ddc942ef3cc550ec972733e53))
244
- * refactor tests and add delete tests ([dd16ac71](https://github.com/badbatch/getta/commit/dd16ac71027c146efc6f1fc86f4771b3e5390c92))
245
- * finishing get method unit tests ([1f6ca8b5](https://github.com/badbatch/getta/commit/1f6ca8b5d558cb1ee77bd7ed8447c5c44a9796b6))
246
- * adding redirect unit tests` ([44daefcc](https://github.com/badbatch/getta/commit/44daefccb945f1e0d1ec4761013d9e764cb4d9cc))
247
- * adding not found status code test ([4f801f3c](https://github.com/badbatch/getta/commit/4f801f3c654ad1242fcae655aaeea7460a6469db))
248
- * refactor unit test structure ([c9b786d3](https://github.com/badbatch/getta/commit/c9b786d31a6d1bd654aba9cab94319bebe950172))
249
- * adding tests to get method ([8c08fc8b](https://github.com/badbatch/getta/commit/8c08fc8b2a6017eaf77011855d817f3359891416))
250
-
package/jest.setup.js DELETED
@@ -1,10 +0,0 @@
1
- const { consts, loadRepositoryConfig } = require('@repodog/config-helpers');
2
-
3
- const { REACT } = consts;
4
- const { features } = loadRepositoryConfig();
5
-
6
- if (features.includes(REACT)) {
7
- const Enzyme = require('enzyme'); // eslint-disable-line
8
- const Adapter = require('enzyme-adapter-react-16'); // eslint-disable-line
9
- Enzyme.configure({ adapter: new Adapter() });
10
- }
@@ -1,2 +0,0 @@
1
- import e from"@babel/runtime/helpers/defineProperty";import t from"lodash/merge";import r from"lodash/castArray";import"core-js/modules/es.promise.js";import a from"md5";import s from"query-string";const i="arrayBuffer",h="blob",o="formData",c="json",n="text",u={ARRAY_BUFFER_FORMAT:"arrayBuffer",BLOB_FORMAT:"blob",FORM_DATA_FORMAT:"formData",JSON_FORMAT:c,TEXT_FORMAT:"text"},d=e=>e,l=5e3,m={"content-type":"application/json"},_=5,p=3,T=/({type})|({id})|({id,\+})|({brief\|standard})/g,R=/({[a-zA-Z0-9_]+\?})/g,f=50,g=100,y="Getta expected to receive 'basePath' in the constructor options,\n but recevied undefined.",v="The request exceeded the maximum number of redirects, which is",q="The request exceeded the maximum number of retries, which is",E="Getta expected to receive 'get', 'post', 'put' or 'delete', but received",b="The requested resource could not been found.",P="The request timed out. Getta did not get a response within",x="get",w="post",C="put",L="delete",k=["get","post","put","delete"],D="information",$="successful",A="redirection",O="clientError",j="serverError",S=304,H=404,M="Cookie",Q="ETag",F="Location",G="If-None-Match",W="Cache-Control",B="request_sent",N="response_received";function I(e,t,r){const a=Object.keys(t);return e.replace(r,e=>a.reduce((r,a)=>e.includes(a)?t[a]:r,""))}function U(e,t,{optionalPathTemplateRegExp:r,pathTemplateCallback:a,pathTemplateData:i,pathTemplateRegExp:h,queryParams:o}){const c=e.endsWith("/")||t.startsWith("/")?"":"/";let n=`${e}${c}${t}`;if(i&&(n=a(n,i,h)),n=n.replace(r,""),n.endsWith("/")&&(n=n.substring(0,n.length-1)),o&&Object.keys(o).length){n=`${n}${s.extract(n)?"&":"?"}${s.stringify(o)}`}return n}class z{constructor(t){e(this,"_basePath",void 0),e(this,"_bodyParser",void 0),e(this,"_cache",void 0),e(this,"_conditionalRequestsEnabled",void 0),e(this,"_fetchTimeout",void 0),e(this,"_headers",void 0),e(this,"_log",void 0),e(this,"_maxRedirects",void 0),e(this,"_maxRetries",void 0),e(this,"_optionalPathTemplateRegExp",void 0),e(this,"_pathTemplateCallback",void 0),e(this,"_pathTemplateRegExp",void 0),e(this,"_performance",void 0),e(this,"_queryParams",void 0),e(this,"_rateLimitCount",0),e(this,"_rateLimitedRequestQueue",[]),e(this,"_rateLimitPerSecond",void 0),e(this,"_rateLimitTimer",null),e(this,"_requestRetryWait",void 0),e(this,"_requestTracker",{active:[],pending:new Map}),e(this,"_streamReader",void 0);const{basePath:r,bodyParser:a=d,cache:s,enableConditionalRequests:i=!0,fetchTimeout:h=l,headers:o,log:n,maxRedirects:u=_,maxRetries:v=p,optionalPathTemplateRegExp:q=R,pathTemplateCallback:E=I,pathTemplateRegExp:b=T,performance:P,queryParams:x={},rateLimitPerSecond:w=f,requestRetryWait:C=g,streamReader:L=c}=t;if(!r)throw new Error(y);this._basePath=r,this._bodyParser=a,this._cache=s,this._conditionalRequestsEnabled=i,this._fetchTimeout=h,this._headers={...m,...o||{}},this._log=n,this._maxRedirects=u,this._maxRetries=v,this._optionalPathTemplateRegExp=q,this._pathTemplateCallback=E,this._pathTemplateRegExp=b,this._performance=P,this._queryParams=x,this._rateLimitPerSecond=w,this._requestRetryWait=C,this._streamReader=L}get cache(){return this._cache}createShortcut(e,r,{method:a,...s}){if(!k.includes(a))throw new Error("Getta expected to receive 'get', 'post', 'put' or 'delete', but received "+a);this[e]=async({method:e,...i}={},h)=>this[null!=e?e:a](r,t({},s,i),h)}async delete(e,t={},r){return this._delete(e,t,r)}async get(e,t={},r){return this._get(e,t,r)}async post(e,t,r){return this._request(e,{...t,method:"post"},r)}async put(e,t,r){return this._request(e,{...t,method:"put"},r)}_addRequestToRateLimitedQueue(e,t,r){return new Promise(a=>{this._rateLimitedRequestQueue.push([a,e,t,r])})}async _cacheEntryDelete(e){if(!this._cache)return!1;try{return await this._cache.delete(e)}catch(e){return Promise.reject(e)}}async _cacheEntryGet(e){if(this._cache)try{return await this._cache.get(e)}catch(e){return Promise.reject(e)}}async _cacheEntryHas(e){if(!this._cache)return!1;try{return await this._cache.has(e)}catch(e){return!1}}async _cacheEntrySet(e,t,r){if(this._cache)try{return await this._cache.set(e,t,{cacheHeaders:r})}catch(e){return Promise.reject(e)}}async _delete(e,{headers:t={},pathTemplateData:r,queryParams:s={},...i},h){const o=U(this._basePath,e,{optionalPathTemplateRegExp:this._optionalPathTemplateRegExp,pathTemplateCallback:this._pathTemplateCallback,pathTemplateData:r,pathTemplateRegExp:this._pathTemplateRegExp,queryParams:{...this._queryParams,...s}}),c=a(o);return await this._cacheEntryHas(c)&&this._cacheEntryDelete(c),this._fetch(o,{headers:{...this._headers,...t},method:"delete",...i},h)}async _fetch(e,t,a={}){a.startTime=this._performance.now();try{const{redirects:r,retries:s,...i}=t;return await new Promise(async(h,o)=>{const c=setTimeout(()=>{o(new Error(`${P} ${this._fetchTimeout}ms.`))},this._fetchTimeout);if(this._rateLimit(),!(this._rateLimitCount<this._rateLimitPerSecond))return clearTimeout(c),void h(await this._addRequestToRateLimitedQueue(e,t,a));var n;r||s||(null===(n=this._log)||void 0===n||n.call(this,"request_sent",{context:{redirects:r,retries:s,url:e,...i,...a},stats:{startTime:a.startTime}}));const u=await fetch(e,i);clearTimeout(c);const{headers:d,status:l}=u,m=function(e){switch(!0){case e<200:return"information";case e<300:return"successful";case e<400:return"redirection";case e<500:return"clientError";default:return"serverError"}}(l);if("redirection"===m&&d.get("Location"))return void h(await this._fetchRedirectHandler(u,d.get("Location"),{redirects:r,status:l,...i},a));if("serverError"===m)return void h(await this._fetchRetryHandler(u,e,{retries:s,...i},a));const _=u;try{_.data=u.body?this._bodyParser(await u[this._streamReader]()):void 0,this._logResponse(_,e,t,a),h(_)}catch(t){o([t,new Error(`Unable to ${i.method} ${e} due to previous error`)])}})}catch(s){const i={errors:r(s)};return this._logResponse(i,e,t,a),i}}async _fetchRedirectHandler(e,t,r,a){const{method:s,redirects:i=1,status:h,...o}=r;if(i===this._maxRedirects){const s=e;return s.errors=[new Error(`The request exceeded the maximum number of redirects, which is ${this._maxRedirects}.`)],this._logResponse(s,t,r,a),s}const c=303===h?"get":s;return this._fetch(t,{method:c,redirects:i+1,...o})}async _fetchRetryHandler(e,t,r,a){const{retries:s=1,...i}=r;if(s===this._maxRetries){const s=e;return s.errors=[new Error(`The request exceeded the maximum number of retries, which is ${this._maxRetries}.`)],this._logResponse(s,t,r,a),s}var h;return await(h=this._requestRetryWait,new Promise(e=>setTimeout(e,h))),this._fetch(t,{retries:s+1,...i})}async _get(e,{headers:t={},pathTemplateData:r,queryParams:s={}},i){const h=U(this._basePath,e,{optionalPathTemplateRegExp:this._optionalPathTemplateRegExp,pathTemplateCallback:this._pathTemplateCallback,pathTemplateData:r,pathTemplateRegExp:this._pathTemplateRegExp,queryParams:{...this._queryParams,...s}}),o=a(h),c=await this._cacheEntryHas(o);if(c){if(function(e){var t,r,a;return!(null!==(t=null==e||null===(r=e.metadata)||void 0===r||null===(a=r.cacheControl)||void 0===a?void 0:a.noCache)&&void 0!==t&&t)&&e.checkTTL()}(c))return{data:await this._cacheEntryGet(o),headers:new Headers({"cache-control":c.printCacheControl()})};if(this._conditionalRequestsEnabled){var n,u;const e=null!==(n=null==c||null===(u=c.metadata)||void 0===u?void 0:u.etag)&&void 0!==n?n:null;e&&(t["If-None-Match"]=e)}}const d=this._trackRequest(o);return d||this._getResolve(o,await this._fetch(h,{headers:{...this._headers,...t},method:"get"},i))}async _getResolve(e,t){const{data:r,headers:a,status:s}=t;if(404===s)this._cacheEntryDelete(e),t.errors||(t.errors=[]),t.errors.push(new Error("The requested resource could not been found."));else if(304===s&&a){const r=await this._cacheEntryGet(e);r&&(this._cacheEntrySet(e,r,{cacheControl:a.get("Cache-Control")||void 0,etag:a.get("ETag")||void 0}),t.data=r)}else r&&a&&this._cacheEntrySet(e,r,{cacheControl:a.get("Cache-Control")||void 0,etag:a.get("ETag")||void 0});return this._resolvePendingRequests(e,t),this._requestTracker.active=this._requestTracker.active.filter(t=>t!==e),t}_logResponse(e,t,r,a){var s;const{data:i,errors:h,headers:o,status:c}=e,{redirects:n,retries:u}=r,{startTime:d,...l}=a,m=this._performance.now(),_=m-d;null===(s=this._log)||void 0===s||s.call(this,"response_received",{context:{body:i?{data:i}:{errors:null!=h?h:[]},headers:o,method:r.method,redirects:n,retries:u,status:c,url:t,...l},stats:{duration:_,endTime:m,startTime:d}})}_rateLimit(){this._rateLimitTimer||(this._rateLimitTimer=setTimeout(()=>{this._rateLimitTimer=null,this._rateLimitCount=0,this._rateLimitedRequestQueue.length&&this._releaseRateLimitedRequestQueue()},1e3)),this._rateLimitCount+=1}_releaseRateLimitedRequestQueue(){this._rateLimitedRequestQueue.forEach(async([e,t,r,a])=>{e(await this._fetch(t,r,a))}),this._rateLimitedRequestQueue=[]}async _request(e,{body:t,headers:r,method:a,pathTemplateData:s,queryParams:i,...h},o){const c=U(this._basePath,e,{optionalPathTemplateRegExp:this._optionalPathTemplateRegExp,pathTemplateCallback:this._pathTemplateCallback,pathTemplateData:s,pathTemplateRegExp:this._pathTemplateRegExp,queryParams:{...this._queryParams,...i}});return this._fetch(c,{body:t,headers:{...this._headers,...r},method:a,...h},o)}_resolvePendingRequests(e,t){const r=this._requestTracker.pending.get(e);r&&(r.forEach(({resolve:e})=>{e(t)}),this._requestTracker.pending.delete(e))}_setPendingRequest(e,t){let r=this._requestTracker.pending.get(e);r||(r=[]),r.push(t),this._requestTracker.pending.set(e,r)}_trackRequest(e){if(this._requestTracker.active.includes(e))return new Promise(t=>{this._setPendingRequest(e,{resolve:t})});this._requestTracker.active.push(e)}}const J=(e,t)=>{const r=new z(e);return t?(Object.keys(t).forEach(e=>{r.createShortcut(e,...t[e])}),r):r};export{i as ARRAY_BUFFER_FORMAT,h as BLOB_FORMAT,W as CACHE_CONTROL_HEADER,O as CLIENT_ERROR_REPSONSE,M as COOKIE_HEADER,d as DEFAULT_BODY_PARSER,l as DEFAULT_FETCH_TIMEOUT,m as DEFAULT_HEADERS,_ as DEFAULT_MAX_REDIRECTS,p as DEFAULT_MAX_RETRIES,T as DEFAULT_PATH_TEMPLATE_REGEX,f as DEFAULT_RATE_LIMIT,g as DEFAULT_REQUEST_RETRY_WAIT,L as DELETE_METHOD,Q as ETAG_HEADER,k as FETCH_METHODS,P as FETCH_TIMEOUT_ERROR,o as FORM_DATA_FORMAT,x as GET_METHOD,z as Getta,G as IF_NONE_MATCH_HEADER,D as INFORMATION_REPSONSE,E as INVALID_FETCH_METHOD_ERROR,c as JSON_FORMAT,F as LOCATION_HEADER,v as MAX_REDIRECTS_EXCEEDED_ERROR,q as MAX_RETRIES_EXCEEDED_ERROR,y as MISSING_BASE_PATH_ERROR,H as NOT_FOUND_STATUS_CODE,S as NOT_MODIFIED_STATUS_CODE,R as OPTIONAL_PATH_TEMPLATE_REGEX,w as POST_METHOD,C as PUT_METHOD,A as REDIRECTION_REPSONSE,B as REQUEST_SENT,b as RESOURCE_NOT_FOUND_ERROR,N as RESPONSE_RECEIVED,j as SERVER_ERROR_REPSONSE,u as STREAM_READERS,$ as SUCCESSFUL_REPSONSE,n as TEXT_FORMAT,J as createRestClient,I as defaultPathTemplateCallback};
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../getta/src/constants.ts","../getta/src/helpers/default-path-template-callback/index.ts","../getta/src/helpers/build-endpoint/index.ts","../getta/src/main.ts","../getta/src/helpers/get-response-group/index.ts","../getta/src/helpers/delay/index.ts","../getta/src/helpers/is-cacheability-valid/index.ts"],"sourcesContent":["import { PlainObject } from \"@repodog/types\";\n\nexport const ARRAY_BUFFER_FORMAT = \"arrayBuffer\" as const;\nexport const BLOB_FORMAT = \"blob\" as const;\nexport const FORM_DATA_FORMAT = \"formData\" as const;\nexport const JSON_FORMAT = \"json\" as const;\nexport const TEXT_FORMAT = \"text\" as const;\n\nexport const STREAM_READERS = {\n ARRAY_BUFFER_FORMAT,\n BLOB_FORMAT,\n FORM_DATA_FORMAT,\n JSON_FORMAT,\n TEXT_FORMAT,\n};\n\nexport const DEFAULT_BODY_PARSER = (body: PlainObject) => body;\nexport const DEFAULT_FETCH_TIMEOUT = 5000 as const;\nexport const DEFAULT_HEADERS = { \"content-type\": \"application/json\" };\nexport const DEFAULT_MAX_REDIRECTS = 5 as const;\nexport const DEFAULT_MAX_RETRIES = 3 as const;\nexport const DEFAULT_PATH_TEMPLATE_REGEX = /({type})|({id})|({id,\\+})|({brief\\|standard})/g;\nexport const OPTIONAL_PATH_TEMPLATE_REGEX = /({[a-zA-Z0-9_]+\\?})/g;\nexport const DEFAULT_RATE_LIMIT = 50;\nexport const DEFAULT_REQUEST_RETRY_WAIT = 100;\n\nexport const MISSING_BASE_PATH_ERROR = `Getta expected to receive 'basePath' in the constructor options,\n but recevied undefined.`;\n\nexport const MAX_REDIRECTS_EXCEEDED_ERROR = \"The request exceeded the maximum number of redirects, which is\";\n\nexport const MAX_RETRIES_EXCEEDED_ERROR = \"The request exceeded the maximum number of retries, which is\";\n\nexport const INVALID_FETCH_METHOD_ERROR = \"Getta expected to receive 'get', 'post', 'put' or 'delete', but received\";\n\nexport const RESOURCE_NOT_FOUND_ERROR = \"The requested resource could not been found.\";\n\nexport const FETCH_TIMEOUT_ERROR = \"The request timed out. Getta did not get a response within\";\n\nexport const GET_METHOD = \"get\" as const;\nexport const POST_METHOD = \"post\" as const;\nexport const PUT_METHOD = \"put\" as const;\nexport const DELETE_METHOD = \"delete\" as const;\n\nexport const FETCH_METHODS = [GET_METHOD, POST_METHOD, PUT_METHOD, DELETE_METHOD];\n\nexport const INFORMATION_REPSONSE = \"information\" as const;\nexport const SUCCESSFUL_REPSONSE = \"successful\" as const;\nexport const REDIRECTION_REPSONSE = \"redirection\" as const;\nexport const CLIENT_ERROR_REPSONSE = \"clientError\" as const;\nexport const SERVER_ERROR_REPSONSE = \"serverError\" as const;\n\nexport const NOT_MODIFIED_STATUS_CODE = 304 as const;\nexport const NOT_FOUND_STATUS_CODE = 404 as const;\n\nexport const COOKIE_HEADER = \"Cookie\" as const;\nexport const ETAG_HEADER = \"ETag\" as const;\nexport const LOCATION_HEADER = \"Location\" as const;\nexport const IF_NONE_MATCH_HEADER = \"If-None-Match\" as const;\nexport const CACHE_CONTROL_HEADER = \"Cache-Control\" as const;\n\nexport const REQUEST_SENT = \"request_sent\" as const;\nexport const RESPONSE_RECEIVED = \"response_received\" as const;\n","import { StringObject } from \"@repodog/types\";\n\nexport default function defaultPathTemplateCallback(\n pathTemplate: string,\n data: StringObject,\n pathTemplateRegExp: RegExp,\n) {\n const dataKeys = Object.keys(data);\n\n return pathTemplate.replace(pathTemplateRegExp, match => {\n return dataKeys.reduce((value, key) => {\n if (match.includes(key)) return data[key];\n return value;\n }, \"\");\n });\n}\n","import queryString from \"query-string\";\nimport { BuildEndpointOptions } from \"./types\";\n\nexport default function buildEndpoint(\n basePath: string,\n path: string,\n {\n optionalPathTemplateRegExp,\n pathTemplateCallback,\n pathTemplateData,\n pathTemplateRegExp,\n queryParams,\n }: BuildEndpointOptions,\n) {\n const pathJoiner = basePath.endsWith(\"/\") || path.startsWith(\"/\") ? \"\" : \"/\";\n let endpoint = `${basePath}${pathJoiner}${path}`;\n\n if (pathTemplateData) {\n endpoint = pathTemplateCallback(endpoint, pathTemplateData, pathTemplateRegExp);\n }\n\n endpoint = endpoint.replace(optionalPathTemplateRegExp, \"\");\n\n if (endpoint.endsWith(\"/\")) {\n endpoint = endpoint.substring(0, endpoint.length - 1);\n }\n\n if (queryParams && Object.keys(queryParams).length) {\n const queryJoin = queryString.extract(endpoint) ? \"&\" : \"?\";\n endpoint = `${endpoint}${queryJoin}${queryString.stringify(queryParams)}`;\n }\n\n return endpoint;\n}\n","import Cachemap, { CacheHeaders } from \"@cachemap/core\";\nimport { Func, PlainObject, StringObject } from \"@repodog/types\";\nimport Cacheability from \"cacheability\";\nimport { castArray, merge } from \"lodash\";\nimport md5 from \"md5\";\nimport { Required } from \"utility-types\";\nimport {\n CACHE_CONTROL_HEADER,\n DEFAULT_BODY_PARSER,\n DEFAULT_FETCH_TIMEOUT,\n DEFAULT_HEADERS,\n DEFAULT_MAX_REDIRECTS,\n DEFAULT_MAX_RETRIES,\n DEFAULT_PATH_TEMPLATE_REGEX,\n DEFAULT_RATE_LIMIT,\n DEFAULT_REQUEST_RETRY_WAIT,\n DELETE_METHOD,\n ETAG_HEADER,\n FETCH_METHODS,\n FETCH_TIMEOUT_ERROR,\n GET_METHOD,\n IF_NONE_MATCH_HEADER,\n INVALID_FETCH_METHOD_ERROR,\n JSON_FORMAT,\n LOCATION_HEADER,\n MAX_REDIRECTS_EXCEEDED_ERROR,\n MAX_RETRIES_EXCEEDED_ERROR,\n MISSING_BASE_PATH_ERROR,\n NOT_FOUND_STATUS_CODE,\n NOT_MODIFIED_STATUS_CODE,\n OPTIONAL_PATH_TEMPLATE_REGEX,\n POST_METHOD,\n PUT_METHOD,\n REDIRECTION_REPSONSE,\n REQUEST_SENT,\n RESOURCE_NOT_FOUND_ERROR,\n RESPONSE_RECEIVED,\n SERVER_ERROR_REPSONSE,\n} from \"./constants\";\nimport buildEndpoint from \"./helpers/build-endpoint\";\nimport defaultPathTemplateCallback from \"./helpers/default-path-template-callback\";\nimport delay from \"./helpers/delay\";\nimport getResponseGroup from \"./helpers/get-response-group\";\nimport isCacheabilityValid from \"./helpers/is-cacheability-valid\";\nimport {\n ConstructorOptions,\n FetchOptions,\n FetchRedirectHandlerOptions,\n FetchResponse,\n Log,\n PathTemplateCallback,\n PendingRequestResolver,\n PendingRequestResolvers,\n Performance,\n RequestOptions,\n RequestQueue,\n RequestTracker,\n ShortcutProperties,\n Shortcuts,\n StreamReader,\n} from \"./types\";\n\nexport class Getta {\n private _basePath: string;\n private _bodyParser: Func;\n private _cache?: Cachemap;\n private _conditionalRequestsEnabled: boolean;\n private _fetchTimeout: number;\n private _headers: StringObject;\n private _log: Log | undefined;\n private _maxRedirects: number;\n private _maxRetries: number;\n private _optionalPathTemplateRegExp: RegExp;\n private _pathTemplateCallback: PathTemplateCallback;\n private _pathTemplateRegExp: RegExp;\n private _performance: Performance;\n private _queryParams: PlainObject;\n private _rateLimitCount: number = 0;\n private _rateLimitedRequestQueue: RequestQueue = [];\n private _rateLimitPerSecond: number;\n private _rateLimitTimer: NodeJS.Timer | null = null;\n private _requestRetryWait: number;\n private _requestTracker: RequestTracker = { active: [], pending: new Map() };\n private _streamReader: StreamReader;\n\n constructor(options: ConstructorOptions) {\n const {\n basePath,\n bodyParser = DEFAULT_BODY_PARSER,\n cache,\n enableConditionalRequests = true,\n fetchTimeout = DEFAULT_FETCH_TIMEOUT,\n headers,\n log,\n maxRedirects = DEFAULT_MAX_REDIRECTS,\n maxRetries = DEFAULT_MAX_RETRIES,\n optionalPathTemplateRegExp = OPTIONAL_PATH_TEMPLATE_REGEX,\n pathTemplateCallback = defaultPathTemplateCallback,\n pathTemplateRegExp = DEFAULT_PATH_TEMPLATE_REGEX,\n performance,\n queryParams = {},\n rateLimitPerSecond = DEFAULT_RATE_LIMIT,\n requestRetryWait = DEFAULT_REQUEST_RETRY_WAIT,\n streamReader = JSON_FORMAT,\n } = options;\n\n if (!basePath) {\n throw new Error(MISSING_BASE_PATH_ERROR);\n }\n\n this._basePath = basePath;\n this._bodyParser = bodyParser;\n this._cache = cache;\n this._conditionalRequestsEnabled = enableConditionalRequests;\n this._fetchTimeout = fetchTimeout;\n this._headers = { ...DEFAULT_HEADERS, ...(headers || {}) };\n this._log = log;\n this._maxRedirects = maxRedirects;\n this._maxRetries = maxRetries;\n this._optionalPathTemplateRegExp = optionalPathTemplateRegExp;\n this._pathTemplateCallback = pathTemplateCallback;\n this._pathTemplateRegExp = pathTemplateRegExp;\n this._performance = performance;\n this._queryParams = queryParams;\n this._rateLimitPerSecond = rateLimitPerSecond;\n this._requestRetryWait = requestRetryWait;\n this._streamReader = streamReader;\n }\n\n get cache(): Cachemap | undefined {\n return this._cache;\n }\n\n public createShortcut(name: string, path: string, { method, ...otherOptions }: Required<RequestOptions, \"method\">) {\n if (!FETCH_METHODS.includes(method)) {\n throw new Error(`${INVALID_FETCH_METHOD_ERROR} ${method}`);\n }\n\n // @ts-ignore\n this[name] = async <Resource extends PlainObject>(\n { method: requestMethod, ...otherOptionOverrides }: RequestOptions = {},\n context?: PlainObject,\n ) =>\n // @ts-ignore\n this[requestMethod ?? method](path, merge({}, otherOptions, otherOptionOverrides), context) as Promise<\n FetchResponse<Resource>\n >;\n }\n\n public async delete(path: string, options: Omit<RequestOptions, \"method\"> = {}, context?: PlainObject) {\n return this._delete(path, options, context);\n }\n\n public async get(path: string, options: Omit<RequestOptions, \"method\"> = {}, context?: PlainObject) {\n return this._get(path, options, context);\n }\n\n public async post(path: string, options: Omit<Required<RequestOptions, \"body\">, \"method\">, context?: PlainObject) {\n return this._request(path, { ...options, method: POST_METHOD }, context);\n }\n\n public async put(path: string, options: Omit<Required<RequestOptions, \"body\">, \"methood\">, context?: PlainObject) {\n return this._request(path, { ...options, method: PUT_METHOD }, context);\n }\n\n private _addRequestToRateLimitedQueue(endpoint: string, options: FetchOptions, context: PlainObject) {\n return new Promise((resolve: (value: FetchResponse) => void) => {\n this._rateLimitedRequestQueue.push([resolve, endpoint, options, context]);\n });\n }\n\n private async _cacheEntryDelete(requestHash: string): Promise<boolean> {\n if (!this._cache) return false;\n\n try {\n return await this._cache.delete(requestHash);\n } catch (errors) {\n return Promise.reject(errors);\n }\n }\n\n private async _cacheEntryGet(requestHash: string): Promise<PlainObject | undefined> {\n if (!this._cache) return undefined;\n\n try {\n return await this._cache.get(requestHash);\n } catch (errors) {\n return Promise.reject(errors);\n }\n }\n\n private async _cacheEntryHas(requestHash: string): Promise<Cacheability | false> {\n if (!this._cache) return false;\n\n try {\n return await this._cache.has(requestHash);\n } catch (error) {\n return false;\n }\n }\n\n private async _cacheEntrySet(requestHash: string, data: PlainObject, cacheHeaders: CacheHeaders): Promise<void> {\n if (!this._cache) return undefined;\n\n try {\n return await this._cache.set(requestHash, data, { cacheHeaders });\n } catch (error) {\n return Promise.reject(error);\n }\n }\n\n private async _delete(\n path: string,\n { headers = {}, pathTemplateData, queryParams = {}, ...rest }: Omit<RequestOptions, \"method\">,\n context?: PlainObject,\n ) {\n const endpoint = buildEndpoint(this._basePath, path, {\n optionalPathTemplateRegExp: this._optionalPathTemplateRegExp,\n pathTemplateCallback: this._pathTemplateCallback,\n pathTemplateData,\n pathTemplateRegExp: this._pathTemplateRegExp,\n queryParams: { ...this._queryParams, ...queryParams },\n });\n\n const requestHash = md5(endpoint);\n const cacheability = await this._cacheEntryHas(requestHash);\n\n if (cacheability) {\n this._cacheEntryDelete(requestHash);\n }\n\n return this._fetch(\n endpoint,\n {\n headers: { ...this._headers, ...headers },\n method: DELETE_METHOD,\n ...rest,\n },\n context,\n );\n }\n\n private async _fetch(endpoint: string, options: FetchOptions, context: PlainObject = {}): Promise<FetchResponse> {\n context.startTime = this._performance.now();\n\n try {\n const { redirects, retries, ...rest } = options;\n return await new Promise(async (resolve: (value: FetchResponse) => void, reject) => {\n const fetchTimer = setTimeout(() => {\n reject(new Error(`${FETCH_TIMEOUT_ERROR} ${this._fetchTimeout}ms.`));\n }, this._fetchTimeout);\n\n this._rateLimit();\n\n if (!(this._rateLimitCount < this._rateLimitPerSecond)) {\n clearTimeout(fetchTimer);\n resolve(await this._addRequestToRateLimitedQueue(endpoint, options, context));\n return;\n }\n\n if (!redirects && !retries) {\n this._log?.(REQUEST_SENT, {\n context: { redirects, retries, url: endpoint, ...rest, ...context },\n stats: { startTime: context.startTime },\n });\n }\n\n const res = await fetch(endpoint, rest);\n\n clearTimeout(fetchTimer);\n\n const { headers, status } = res;\n const responseGroup = getResponseGroup(status);\n\n if (responseGroup === REDIRECTION_REPSONSE && headers.get(LOCATION_HEADER)) {\n resolve(\n await this._fetchRedirectHandler(\n res,\n headers.get(LOCATION_HEADER) as string,\n {\n redirects,\n status,\n ...rest,\n },\n context,\n ),\n );\n\n return;\n }\n\n if (responseGroup === SERVER_ERROR_REPSONSE) {\n resolve(\n (await this._fetchRetryHandler(\n res,\n endpoint,\n {\n retries,\n ...rest,\n },\n context,\n )) as FetchResponse,\n );\n\n return;\n }\n\n const fetchRes = res as FetchResponse;\n\n try {\n fetchRes.data = res.body ? this._bodyParser(await res[this._streamReader]()) : undefined;\n this._logResponse(fetchRes, endpoint, options, context);\n resolve(fetchRes);\n } catch (e) {\n reject([e, new Error(`Unable to ${rest.method} ${endpoint} due to previous error`)]);\n }\n });\n } catch (error) {\n const fetchRes = { errors: castArray(error) };\n this._logResponse(fetchRes as FetchResponse, endpoint, options, context);\n return fetchRes as FetchResponse;\n }\n }\n\n private async _fetchRedirectHandler(\n res: Response,\n endpoint: string,\n options: FetchRedirectHandlerOptions,\n context: PlainObject,\n ): Promise<FetchResponse> {\n const { method, redirects = 1, status, ...rest } = options;\n\n if (redirects === this._maxRedirects) {\n const fetchRes = res as FetchResponse;\n fetchRes.errors = [new Error(`${MAX_REDIRECTS_EXCEEDED_ERROR} ${this._maxRedirects}.`)];\n this._logResponse(fetchRes, endpoint, options, context);\n return fetchRes;\n }\n\n const redirectMethod = status === 303 ? GET_METHOD : method;\n return this._fetch(endpoint, { method: redirectMethod, redirects: redirects + 1, ...rest });\n }\n\n private async _fetchRetryHandler(res: Response, endpoint: string, options: FetchOptions, context: PlainObject) {\n const { retries = 1, ...rest } = options;\n\n if (retries === this._maxRetries) {\n const fetchRes = res as FetchResponse;\n fetchRes.errors = [new Error(`${MAX_RETRIES_EXCEEDED_ERROR} ${this._maxRetries}.`)];\n this._logResponse(fetchRes, endpoint, options, context);\n return fetchRes;\n }\n\n await delay(this._requestRetryWait);\n return this._fetch(endpoint, { retries: retries + 1, ...rest });\n }\n\n private async _get(\n path: string,\n { headers = {}, pathTemplateData, queryParams = {} }: Omit<RequestOptions, \"method\">,\n context?: PlainObject,\n ) {\n const endpoint = buildEndpoint(this._basePath, path, {\n optionalPathTemplateRegExp: this._optionalPathTemplateRegExp,\n pathTemplateCallback: this._pathTemplateCallback,\n pathTemplateData,\n pathTemplateRegExp: this._pathTemplateRegExp,\n queryParams: { ...this._queryParams, ...queryParams },\n });\n\n const requestHash = md5(endpoint);\n const cacheability = await this._cacheEntryHas(requestHash);\n\n if (cacheability) {\n if (isCacheabilityValid(cacheability)) {\n return {\n data: await this._cacheEntryGet(requestHash),\n headers: new Headers({ \"cache-control\": cacheability.printCacheControl() }),\n };\n }\n\n if (this._conditionalRequestsEnabled) {\n const etag = cacheability?.metadata?.etag ?? null;\n if (etag) headers[IF_NONE_MATCH_HEADER] = etag;\n }\n }\n\n const pendingRequest = this._trackRequest(requestHash);\n if (pendingRequest) return pendingRequest;\n\n return this._getResolve(\n requestHash,\n await this._fetch(endpoint, { headers: { ...this._headers, ...headers }, method: GET_METHOD }, context),\n );\n }\n\n private async _getResolve(requestHash: string, res: FetchResponse) {\n const { data, headers, status } = res;\n\n if (status === NOT_FOUND_STATUS_CODE) {\n this._cacheEntryDelete(requestHash);\n\n if (!res.errors) {\n res.errors = [];\n }\n\n res.errors.push(new Error(RESOURCE_NOT_FOUND_ERROR));\n } else if (status === NOT_MODIFIED_STATUS_CODE && headers) {\n const cachedData = await this._cacheEntryGet(requestHash);\n\n if (cachedData) {\n this._cacheEntrySet(requestHash, cachedData, {\n cacheControl: headers.get(CACHE_CONTROL_HEADER) || undefined,\n etag: headers.get(ETAG_HEADER) || undefined,\n });\n\n res.data = cachedData;\n }\n } else if (data && headers) {\n this._cacheEntrySet(requestHash, data, {\n cacheControl: headers.get(CACHE_CONTROL_HEADER) || undefined,\n etag: headers.get(ETAG_HEADER) || undefined,\n });\n }\n\n this._resolvePendingRequests(requestHash, res);\n this._requestTracker.active = this._requestTracker.active.filter(value => value !== requestHash);\n return res;\n }\n\n private _logResponse(res: FetchResponse, endpoint: string, options: FetchOptions, context: PlainObject) {\n const { data, errors, headers, status } = res;\n const { redirects, retries } = options;\n const { startTime, ...otherContext } = context;\n\n const endTime = this._performance.now();\n const duration = endTime - startTime;\n\n this._log?.(RESPONSE_RECEIVED, {\n context: {\n body: data ? { data } : { errors: errors ?? [] },\n headers,\n method: options.method,\n redirects,\n retries,\n status,\n url: endpoint,\n ...otherContext,\n },\n stats: { duration, endTime, startTime },\n });\n }\n\n private _rateLimit() {\n if (!this._rateLimitTimer) {\n this._rateLimitTimer = setTimeout(() => {\n this._rateLimitTimer = null;\n this._rateLimitCount = 0;\n\n if (this._rateLimitedRequestQueue.length) {\n this._releaseRateLimitedRequestQueue();\n }\n }, 1000);\n }\n\n this._rateLimitCount += 1;\n }\n\n private _releaseRateLimitedRequestQueue() {\n this._rateLimitedRequestQueue.forEach(async ([resolve, endpoint, options, context]) => {\n // @ts-ignore\n resolve(await this._fetch(endpoint, options, context));\n });\n\n this._rateLimitedRequestQueue = [];\n }\n\n private async _request(\n path: string,\n { body, headers, method, pathTemplateData, queryParams, ...rest }: Required<RequestOptions, \"method\">,\n context?: PlainObject,\n ) {\n const endpoint = buildEndpoint(this._basePath, path, {\n optionalPathTemplateRegExp: this._optionalPathTemplateRegExp,\n pathTemplateCallback: this._pathTemplateCallback,\n pathTemplateData,\n pathTemplateRegExp: this._pathTemplateRegExp,\n queryParams: { ...this._queryParams, ...queryParams },\n });\n\n return this._fetch(\n endpoint,\n {\n body,\n headers: { ...this._headers, ...headers },\n method,\n ...rest,\n },\n context,\n );\n }\n\n private _resolvePendingRequests(requestHash: string, responseData: FetchResponse) {\n const pendingRequests = this._requestTracker.pending.get(requestHash);\n if (!pendingRequests) return;\n\n pendingRequests.forEach(({ resolve }) => {\n resolve(responseData);\n });\n\n this._requestTracker.pending.delete(requestHash);\n }\n\n private _setPendingRequest(requestHash: string, resolver: PendingRequestResolvers) {\n let pending = this._requestTracker.pending.get(requestHash);\n if (!pending) pending = [];\n pending.push(resolver);\n this._requestTracker.pending.set(requestHash, pending);\n }\n\n private _trackRequest(requestHash: string): Promise<FetchResponse> | void {\n if (this._requestTracker.active.includes(requestHash)) {\n return new Promise((resolve: PendingRequestResolver) => {\n this._setPendingRequest(requestHash, { resolve });\n });\n }\n\n this._requestTracker.active.push(requestHash);\n }\n}\n\nexport const createRestClient = <N extends string>(options: ConstructorOptions, shortcuts?: Shortcuts) => {\n const getta = new Getta(options) as Getta & ShortcutProperties<N>;\n if (!shortcuts) return getta;\n\n Object.keys(shortcuts).forEach(key => {\n getta.createShortcut(key, ...shortcuts[key]);\n });\n\n return getta;\n};\n","import {\n CLIENT_ERROR_REPSONSE,\n INFORMATION_REPSONSE,\n REDIRECTION_REPSONSE,\n SERVER_ERROR_REPSONSE,\n SUCCESSFUL_REPSONSE,\n} from \"../../constants\";\n\nexport default function getResponseGroup(status: number) {\n switch (true) {\n case status < 200:\n return INFORMATION_REPSONSE;\n case status < 300:\n return SUCCESSFUL_REPSONSE;\n case status < 400:\n return REDIRECTION_REPSONSE;\n case status < 500:\n return CLIENT_ERROR_REPSONSE;\n default:\n return SERVER_ERROR_REPSONSE;\n }\n}\n","export default function delay(ms: number) {\n return new Promise(resolve => setTimeout(resolve, ms));\n}\n","import Cacheability from \"cacheability\";\n\nexport default function isCacheabilityValid(cacheability: Cacheability) {\n const noCache = cacheability?.metadata?.cacheControl?.noCache ?? false;\n return !noCache && cacheability.checkTTL();\n}\n"],"names":["ARRAY_BUFFER_FORMAT","BLOB_FORMAT","FORM_DATA_FORMAT","JSON_FORMAT","TEXT_FORMAT","STREAM_READERS","DEFAULT_BODY_PARSER","body","DEFAULT_FETCH_TIMEOUT","DEFAULT_HEADERS","DEFAULT_MAX_REDIRECTS","DEFAULT_MAX_RETRIES","DEFAULT_PATH_TEMPLATE_REGEX","OPTIONAL_PATH_TEMPLATE_REGEX","DEFAULT_RATE_LIMIT","DEFAULT_REQUEST_RETRY_WAIT","MISSING_BASE_PATH_ERROR","MAX_REDIRECTS_EXCEEDED_ERROR","MAX_RETRIES_EXCEEDED_ERROR","INVALID_FETCH_METHOD_ERROR","RESOURCE_NOT_FOUND_ERROR","FETCH_TIMEOUT_ERROR","GET_METHOD","POST_METHOD","PUT_METHOD","DELETE_METHOD","FETCH_METHODS","INFORMATION_REPSONSE","SUCCESSFUL_REPSONSE","REDIRECTION_REPSONSE","CLIENT_ERROR_REPSONSE","SERVER_ERROR_REPSONSE","NOT_MODIFIED_STATUS_CODE","NOT_FOUND_STATUS_CODE","COOKIE_HEADER","ETAG_HEADER","LOCATION_HEADER","IF_NONE_MATCH_HEADER","CACHE_CONTROL_HEADER","REQUEST_SENT","RESPONSE_RECEIVED","defaultPathTemplateCallback","pathTemplate","data","pathTemplateRegExp","dataKeys","Object","keys","replace","match","reduce","value","key","includes","buildEndpoint","basePath","path","optionalPathTemplateRegExp","pathTemplateCallback","pathTemplateData","queryParams","pathJoiner","endsWith","startsWith","endpoint","substring","length","queryString","extract","stringify","Getta","constructor","options","active","pending","Map","bodyParser","cache","enableConditionalRequests","fetchTimeout","headers","log","maxRedirects","maxRetries","performance","rateLimitPerSecond","requestRetryWait","streamReader","Error","_basePath","_bodyParser","_cache","_conditionalRequestsEnabled","_fetchTimeout","_headers","_log","_maxRedirects","_maxRetries","_optionalPathTemplateRegExp","_pathTemplateCallback","_pathTemplateRegExp","_performance","_queryParams","_rateLimitPerSecond","_requestRetryWait","_streamReader","this","createShortcut","name","method","otherOptions","async","requestMethod","otherOptionOverrides","context","_merge","_delete","_get","_request","_addRequestToRateLimitedQueue","Promise","resolve","_rateLimitedRequestQueue","push","requestHash","delete","errors","reject","get","has","error","cacheHeaders","set","rest","md5","_cacheEntryHas","_cacheEntryDelete","_fetch","startTime","now","redirects","retries","fetchTimer","setTimeout","_rateLimit","_rateLimitCount","clearTimeout","url","stats","res","fetch","status","responseGroup","getResponseGroup","_fetchRedirectHandler","_fetchRetryHandler","fetchRes","undefined","_logResponse","e","_castArray","redirectMethod","ms","cacheability","metadata","_cacheability$metadat2","cacheControl","_cacheability$metadat3","noCache","checkTTL","isCacheabilityValid","_cacheEntryGet","Headers","printCacheControl","etag","pendingRequest","_trackRequest","_getResolve","cachedData","_cacheEntrySet","_resolvePendingRequests","_requestTracker","filter","otherContext","endTime","duration","_rateLimitTimer","_releaseRateLimitedRequestQueue","forEach","responseData","pendingRequests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