@clickup/rest-client 2.10.292

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 (137) hide show
  1. package/.eslintrc.base.js +412 -0
  2. package/.eslintrc.js +5 -0
  3. package/LICENSE +22 -0
  4. package/README.md +121 -0
  5. package/dist/RestClient.d.ts +154 -0
  6. package/dist/RestClient.d.ts.map +1 -0
  7. package/dist/RestClient.js +361 -0
  8. package/dist/RestClient.js.map +1 -0
  9. package/dist/RestOptions.d.ts +143 -0
  10. package/dist/RestOptions.d.ts.map +1 -0
  11. package/dist/RestOptions.js +63 -0
  12. package/dist/RestOptions.js.map +1 -0
  13. package/dist/RestRequest.d.ts +81 -0
  14. package/dist/RestRequest.d.ts.map +1 -0
  15. package/dist/RestRequest.js +367 -0
  16. package/dist/RestRequest.js.map +1 -0
  17. package/dist/RestResponse.d.ts +37 -0
  18. package/dist/RestResponse.d.ts.map +1 -0
  19. package/dist/RestResponse.js +56 -0
  20. package/dist/RestResponse.js.map +1 -0
  21. package/dist/RestStream.d.ts +29 -0
  22. package/dist/RestStream.d.ts.map +1 -0
  23. package/dist/RestStream.js +85 -0
  24. package/dist/RestStream.js.map +1 -0
  25. package/dist/errors/RestContentSizeOverLimitError.d.ts +4 -0
  26. package/dist/errors/RestContentSizeOverLimitError.d.ts.map +1 -0
  27. package/dist/errors/RestContentSizeOverLimitError.js +10 -0
  28. package/dist/errors/RestContentSizeOverLimitError.js.map +1 -0
  29. package/dist/errors/RestError.d.ts +4 -0
  30. package/dist/errors/RestError.d.ts.map +1 -0
  31. package/dist/errors/RestError.js +10 -0
  32. package/dist/errors/RestError.js.map +1 -0
  33. package/dist/errors/RestRateLimitError.d.ts +7 -0
  34. package/dist/errors/RestRateLimitError.d.ts.map +1 -0
  35. package/dist/errors/RestRateLimitError.js +14 -0
  36. package/dist/errors/RestRateLimitError.js.map +1 -0
  37. package/dist/errors/RestResponseError.d.ts +13 -0
  38. package/dist/errors/RestResponseError.d.ts.map +1 -0
  39. package/dist/errors/RestResponseError.js +32 -0
  40. package/dist/errors/RestResponseError.js.map +1 -0
  41. package/dist/errors/RestRetriableError.d.ts +7 -0
  42. package/dist/errors/RestRetriableError.d.ts.map +1 -0
  43. package/dist/errors/RestRetriableError.js +14 -0
  44. package/dist/errors/RestRetriableError.js.map +1 -0
  45. package/dist/errors/RestTimeoutError.d.ts +4 -0
  46. package/dist/errors/RestTimeoutError.d.ts.map +1 -0
  47. package/dist/errors/RestTimeoutError.js +10 -0
  48. package/dist/errors/RestTimeoutError.js.map +1 -0
  49. package/dist/errors/RestTokenInvalidError.d.ts +7 -0
  50. package/dist/errors/RestTokenInvalidError.d.ts.map +1 -0
  51. package/dist/errors/RestTokenInvalidError.js +14 -0
  52. package/dist/errors/RestTokenInvalidError.js.map +1 -0
  53. package/dist/helpers/depaginate.d.ts +10 -0
  54. package/dist/helpers/depaginate.d.ts.map +1 -0
  55. package/dist/helpers/depaginate.js +32 -0
  56. package/dist/helpers/depaginate.js.map +1 -0
  57. package/dist/index.d.ts +20 -0
  58. package/dist/index.d.ts.map +1 -0
  59. package/dist/index.js +42 -0
  60. package/dist/index.js.map +1 -0
  61. package/dist/internal/RestFetchReader.d.ts +72 -0
  62. package/dist/internal/RestFetchReader.d.ts.map +1 -0
  63. package/dist/internal/RestFetchReader.js +192 -0
  64. package/dist/internal/RestFetchReader.js.map +1 -0
  65. package/dist/internal/RestRangeUploader.d.ts +24 -0
  66. package/dist/internal/RestRangeUploader.d.ts.map +1 -0
  67. package/dist/internal/RestRangeUploader.js +54 -0
  68. package/dist/internal/RestRangeUploader.js.map +1 -0
  69. package/dist/internal/calcRetryDelay.d.ts +8 -0
  70. package/dist/internal/calcRetryDelay.d.ts.map +1 -0
  71. package/dist/internal/calcRetryDelay.js +44 -0
  72. package/dist/internal/calcRetryDelay.js.map +1 -0
  73. package/dist/internal/inspectPossibleJSON.d.ts +6 -0
  74. package/dist/internal/inspectPossibleJSON.d.ts.map +1 -0
  75. package/dist/internal/inspectPossibleJSON.js +53 -0
  76. package/dist/internal/inspectPossibleJSON.js.map +1 -0
  77. package/dist/internal/prependNewlineIfMultiline.d.ts +2 -0
  78. package/dist/internal/prependNewlineIfMultiline.d.ts.map +1 -0
  79. package/dist/internal/prependNewlineIfMultiline.js +7 -0
  80. package/dist/internal/prependNewlineIfMultiline.js.map +1 -0
  81. package/dist/internal/substituteParams.d.ts +7 -0
  82. package/dist/internal/substituteParams.d.ts.map +1 -0
  83. package/dist/internal/substituteParams.js +24 -0
  84. package/dist/internal/substituteParams.js.map +1 -0
  85. package/dist/internal/throwIfErrorResponse.d.ts +11 -0
  86. package/dist/internal/throwIfErrorResponse.d.ts.map +1 -0
  87. package/dist/internal/throwIfErrorResponse.js +60 -0
  88. package/dist/internal/throwIfErrorResponse.js.map +1 -0
  89. package/dist/internal/toFloatMs.d.ts +2 -0
  90. package/dist/internal/toFloatMs.d.ts.map +1 -0
  91. package/dist/internal/toFloatMs.js +7 -0
  92. package/dist/internal/toFloatMs.js.map +1 -0
  93. package/dist/middlewares/paceRequests.d.ts +9 -0
  94. package/dist/middlewares/paceRequests.d.ts.map +1 -0
  95. package/dist/middlewares/paceRequests.js +36 -0
  96. package/dist/middlewares/paceRequests.js.map +1 -0
  97. package/dist/pacers/Pacer.d.ts +21 -0
  98. package/dist/pacers/Pacer.d.ts.map +1 -0
  99. package/dist/pacers/Pacer.js +3 -0
  100. package/dist/pacers/Pacer.js.map +1 -0
  101. package/dist/pacers/PacerComposite.d.ts +14 -0
  102. package/dist/pacers/PacerComposite.d.ts.map +1 -0
  103. package/dist/pacers/PacerComposite.js +32 -0
  104. package/dist/pacers/PacerComposite.js.map +1 -0
  105. package/dist/pacers/PacerQPS.d.ts +53 -0
  106. package/dist/pacers/PacerQPS.d.ts.map +1 -0
  107. package/dist/pacers/PacerQPS.js +105 -0
  108. package/dist/pacers/PacerQPS.js.map +1 -0
  109. package/dist/tsconfig.tsbuildinfo +1 -0
  110. package/docs/.nojekyll +1 -0
  111. package/docs/README.md +123 -0
  112. package/docs/classes/PacerComposite.md +62 -0
  113. package/docs/classes/PacerQPS.md +75 -0
  114. package/docs/classes/RestClient.md +424 -0
  115. package/docs/classes/RestContentSizeOverLimitError.md +128 -0
  116. package/docs/classes/RestError.md +31 -0
  117. package/docs/classes/RestRateLimitError.md +139 -0
  118. package/docs/classes/RestRequest.md +257 -0
  119. package/docs/classes/RestResponse.md +110 -0
  120. package/docs/classes/RestResponseError.md +110 -0
  121. package/docs/classes/RestRetriableError.md +139 -0
  122. package/docs/classes/RestStream.md +92 -0
  123. package/docs/classes/RestTimeoutError.md +128 -0
  124. package/docs/classes/RestTokenInvalidError.md +138 -0
  125. package/docs/interfaces/Middleware.md +27 -0
  126. package/docs/interfaces/Pacer.md +40 -0
  127. package/docs/interfaces/PacerDelay.md +25 -0
  128. package/docs/interfaces/PacerQPSBackend.md +44 -0
  129. package/docs/interfaces/PacerQPSOptions.md +40 -0
  130. package/docs/interfaces/RestLogEvent.md +95 -0
  131. package/docs/interfaces/RestOptions.md +351 -0
  132. package/docs/interfaces/TokenGetter.md +34 -0
  133. package/docs/modules.md +87 -0
  134. package/jest.config.js +8 -0
  135. package/package.json +42 -0
  136. package/tsconfig.json +39 -0
  137. package/typedoc.json +17 -0
@@ -0,0 +1,72 @@
1
+ import type { RequestInit } from "node-fetch";
2
+ import { Headers } from "node-fetch";
3
+ export interface RestFetchReaderOptions {
4
+ timeoutMs?: number;
5
+ heartbeat?: () => Promise<void>;
6
+ onTimeout?: (reader: RestFetchReader, e: any) => void;
7
+ onAfterRead?: (reader: RestFetchReader) => void;
8
+ }
9
+ /**
10
+ * A low-level stateful reader engine on top of node-fetch which implements
11
+ * "preload first N chars and then leave the rest ready for iteration" pattern,
12
+ * with global timeout for the entire fetching time.
13
+ *
14
+ * Once created, the object MUST be iterated in full to consume the rest of the
15
+ * stream and close the connection. In case you're not interested in its entire
16
+ * content, you must prematurely "return" (close) the iterator.
17
+ *
18
+ * The abstraction is intentionally kept independent on all others, to make it
19
+ * simple and testable separately.
20
+ */
21
+ export default class RestFetchReader {
22
+ private _url;
23
+ private _req;
24
+ private _options;
25
+ private _status;
26
+ private _headers;
27
+ private _textFetched;
28
+ private _textIsPartial;
29
+ private _charsRead;
30
+ constructor(_url: string, _req: RequestInit, _options: RestFetchReaderOptions);
31
+ /**
32
+ * Returns the number of characters read from the stream so far.
33
+ */
34
+ get charsRead(): number;
35
+ /**
36
+ * Returns HTTP status after preload() was called.
37
+ */
38
+ get status(): number;
39
+ /**
40
+ * Returns HTTP headers after preload() was called.
41
+ */
42
+ get headers(): Headers;
43
+ /**
44
+ * Returns the data preloaded so far.
45
+ */
46
+ get textFetched(): string;
47
+ /**
48
+ * If true, then there is a chance that reading more from the stream will
49
+ * return more data.
50
+ */
51
+ get textIsPartial(): boolean;
52
+ /**
53
+ * Reads preloadChars chars or a little bit more from the response and puts
54
+ * them to this.textFetched. Leaves the rest of the data in res.body for
55
+ * future reads if there are more data to fetch (you must consume them or
56
+ * close the stream, otherwise the connection will remain open).
57
+ */
58
+ preload(preloadChars: number): Promise<void>;
59
+ /**
60
+ * Closes the connection.
61
+ */
62
+ close(): Promise<void>;
63
+ /**
64
+ * Returns an async generator for the rest of the data. Must be consumed
65
+ * entirely, otherwise the connection may remain dangling.
66
+ *
67
+ * Memoization is important here, to return the same generator when we call
68
+ * this method multiple times and to not start a new iteration over and over.
69
+ */
70
+ [Symbol.asyncIterator](): AsyncGenerator<string, void, unknown>;
71
+ }
72
+ //# sourceMappingURL=RestFetchReader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RestFetchReader.d.ts","sourceRoot":"","sources":["../../src/internal/RestFetchReader.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAc,EAAE,OAAO,EAAW,MAAM,YAAY,CAAC;AAErD,MAAM,WAAW,sBAAsB;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,EAAE,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;IACtD,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,KAAK,IAAI,CAAC;CACjD;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,OAAO,eAAe;IAQhC,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,QAAQ;IATlB,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,YAAY,CAAM;IAC1B,OAAO,CAAC,cAAc,CAAQ;IAC9B,OAAO,CAAC,UAAU,CAAK;gBAGb,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,WAAW,EACjB,QAAQ,EAAE,sBAAsB;IAG1C;;OAEG;IACH,IAAI,SAAS,WAEZ;IAED;;OAEG;IACH,IAAI,MAAM,WAET;IAED;;OAEG;IACH,IAAI,OAAO,YAEV;IAED;;OAEG;IACH,IAAI,WAAW,IAAI,MAAM,CAExB;IAED;;;OAGG;IACH,IAAI,aAAa,YAEhB;IAED;;;;;OAKG;IACG,OAAO,CAAC,YAAY,EAAE,MAAM;IAmBlC;;OAEG;IACG,KAAK;IAIX;;;;;;OAMG;IAEI,CAAC,MAAM,CAAC,aAAa,CAAC;CA8D9B"}
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
31
+ var __importDefault = (this && this.__importDefault) || function (mod) {
32
+ return (mod && mod.__esModule) ? mod : { "default": mod };
33
+ };
34
+ var _a;
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const abort_controller_1 = __importDefault(require("abort-controller"));
37
+ const fast_typescript_memoize_1 = require("fast-typescript-memoize");
38
+ const node_fetch_1 = __importStar(require("node-fetch"));
39
+ /**
40
+ * A low-level stateful reader engine on top of node-fetch which implements
41
+ * "preload first N chars and then leave the rest ready for iteration" pattern,
42
+ * with global timeout for the entire fetching time.
43
+ *
44
+ * Once created, the object MUST be iterated in full to consume the rest of the
45
+ * stream and close the connection. In case you're not interested in its entire
46
+ * content, you must prematurely "return" (close) the iterator.
47
+ *
48
+ * The abstraction is intentionally kept independent on all others, to make it
49
+ * simple and testable separately.
50
+ */
51
+ class RestFetchReader {
52
+ constructor(_url, _req, _options) {
53
+ this._url = _url;
54
+ this._req = _req;
55
+ this._options = _options;
56
+ this._status = 0;
57
+ this._headers = new node_fetch_1.Headers();
58
+ this._textFetched = "";
59
+ this._textIsPartial = true;
60
+ this._charsRead = 0;
61
+ }
62
+ /**
63
+ * Returns the number of characters read from the stream so far.
64
+ */
65
+ get charsRead() {
66
+ return this._charsRead;
67
+ }
68
+ /**
69
+ * Returns HTTP status after preload() was called.
70
+ */
71
+ get status() {
72
+ return this._status;
73
+ }
74
+ /**
75
+ * Returns HTTP headers after preload() was called.
76
+ */
77
+ get headers() {
78
+ return this._headers;
79
+ }
80
+ /**
81
+ * Returns the data preloaded so far.
82
+ */
83
+ get textFetched() {
84
+ return this._textFetched;
85
+ }
86
+ /**
87
+ * If true, then there is a chance that reading more from the stream will
88
+ * return more data.
89
+ */
90
+ get textIsPartial() {
91
+ return this._textIsPartial;
92
+ }
93
+ /**
94
+ * Reads preloadChars chars or a little bit more from the response and puts
95
+ * them to this.textFetched. Leaves the rest of the data in res.body for
96
+ * future reads if there are more data to fetch (you must consume them or
97
+ * close the stream, otherwise the connection will remain open).
98
+ */
99
+ async preload(preloadChars) {
100
+ const generator = this[Symbol.asyncIterator]();
101
+ try {
102
+ while (this._charsRead < preloadChars) {
103
+ const { value, done } = await generator.next();
104
+ if (done) {
105
+ this._textIsPartial = false;
106
+ await generator.return();
107
+ return;
108
+ }
109
+ this._textFetched += value;
110
+ }
111
+ }
112
+ catch (e) {
113
+ await generator.return();
114
+ throw e;
115
+ }
116
+ }
117
+ /**
118
+ * Closes the connection.
119
+ */
120
+ async close() {
121
+ await this[Symbol.asyncIterator]().return();
122
+ }
123
+ /**
124
+ * Returns an async generator for the rest of the data. Must be consumed
125
+ * entirely, otherwise the connection may remain dangling.
126
+ *
127
+ * Memoization is important here, to return the same generator when we call
128
+ * this method multiple times and to not start a new iteration over and over.
129
+ */
130
+ async *[_a = Symbol.asyncIterator]() {
131
+ var _b, _c, _d, _e;
132
+ const { timeoutMs, onTimeout, onAfterRead } = this._options;
133
+ // Some of react-client users are still on v14 node.
134
+ const controller = typeof AbortController === "undefined"
135
+ ? new abort_controller_1.default()
136
+ : new AbortController();
137
+ const timeout = timeoutMs
138
+ ? setTimeout(() => controller.abort(), timeoutMs)
139
+ : undefined;
140
+ try {
141
+ // DO NOT use fetch(fetchReq) with one argument! It clones the stream
142
+ // which just doesn't work in practice, even with file streams. I wasted
143
+ // 4h on debugging this: fetch(fetchReq.url, fetchReq) works and
144
+ // fetch(fetchReq) doesn't for e.g. Dropbox API and
145
+ // https://stackoverflow.com/a/44577569
146
+ const res = await (0, node_fetch_1.default)(this._url, new node_fetch_1.Request(this._url, {
147
+ ...this._req,
148
+ signal: controller.signal,
149
+ }));
150
+ this._status = res.status;
151
+ this._headers = res.headers;
152
+ // An opinionated choice is made here to always decode the response stream
153
+ // as UTF-8. This is because JSON is by definition a UTF-8 stream. In the
154
+ // future, when we need binary streams, we can tweak it by introducing
155
+ // some intermediate layer and doing some refactoring, but for now it's an
156
+ // overkill. See also
157
+ // https://nodejs.org/api/stream.html#readablesetencodingencoding on how
158
+ // Node streams handle decoding when the returned chunks cross the
159
+ // boundaries of multi-byte characters.
160
+ res.body.setEncoding("utf-8");
161
+ await ((_c = (_b = this._options).heartbeat) === null || _c === void 0 ? void 0 : _c.call(_b));
162
+ for await (const chunk of res.body) {
163
+ await ((_e = (_d = this._options).heartbeat) === null || _e === void 0 ? void 0 : _e.call(_d));
164
+ this._charsRead += chunk.length;
165
+ yield chunk;
166
+ onAfterRead === null || onAfterRead === void 0 ? void 0 : onAfterRead(this);
167
+ }
168
+ }
169
+ catch (e) {
170
+ if (controller.signal.aborted && onTimeout) {
171
+ onTimeout(this, e);
172
+ }
173
+ else {
174
+ throw e;
175
+ }
176
+ }
177
+ finally {
178
+ timeout && clearTimeout(timeout);
179
+ // If someone stops iterating prematurely, we forcefully close the
180
+ // connection in all cases. Theoretically, stopping the iteration on
181
+ // res.body should've closed the connection, but in practice it doesn't
182
+ // happen; it looks like a bug in node-fetch, and thus, we must always use
183
+ // the AbortController in the end.
184
+ controller.abort();
185
+ }
186
+ }
187
+ }
188
+ exports.default = RestFetchReader;
189
+ __decorate([
190
+ (0, fast_typescript_memoize_1.Memoize)()
191
+ ], RestFetchReader.prototype, _a, null);
192
+ //# sourceMappingURL=RestFetchReader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RestFetchReader.js","sourceRoot":"","sources":["../../src/internal/RestFetchReader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wEAAyD;AACzD,qEAAkD;AAElD,yDAAqD;AASrD;;;;;;;;;;;GAWG;AACH,MAAqB,eAAe;IAOlC,YACU,IAAY,EACZ,IAAiB,EACjB,QAAgC;QAFhC,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAa;QACjB,aAAQ,GAAR,QAAQ,CAAwB;QATlC,YAAO,GAAG,CAAC,CAAC;QACZ,aAAQ,GAAG,IAAI,oBAAO,EAAE,CAAC;QACzB,iBAAY,GAAG,EAAE,CAAC;QAClB,mBAAc,GAAG,IAAI,CAAC;QACtB,eAAU,GAAG,CAAC,CAAC;IAMpB,CAAC;IAEJ;;OAEG;IACH,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACH,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,OAAO,CAAC,YAAoB;QAChC,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC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types="node" />
2
+ import type RestClient from "../RestClient";
3
+ /**
4
+ * Sends a series of Content-Range requests to an URL.
5
+ * - The stream size is unknown in advance even theoretically. So we read it
6
+ * with chunkSize+1 bytes chunks (+1 is to know for sure, is there something
7
+ * else left in the stream or not) and then send data with chunkSize bytes
8
+ * chunks.
9
+ * - The last chunk is a terminating one (and we know, which one is the last),
10
+ * so we reflect it in "Content-Range: x-y/S" format setting S to the total
11
+ * number of bytes in the stream.
12
+ */
13
+ export default class RestRangeUploader {
14
+ private _client;
15
+ private _chunkSize;
16
+ private _method;
17
+ private _path;
18
+ private _mimeType;
19
+ private _pos;
20
+ constructor(_client: RestClient, _chunkSize: number, _method: "POST" | "PUT", _path: string, _mimeType: string);
21
+ upload(stream: AsyncIterable<Buffer>): Promise<string | null>;
22
+ private _flush;
23
+ }
24
+ //# sourceMappingURL=RestRangeUploader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RestRangeUploader.d.ts","sourceRoot":"","sources":["../../src/internal/RestRangeUploader.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAE5C;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;IAIlC,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,SAAS;IAPnB,OAAO,CAAC,IAAI,CAAK;gBAGP,OAAO,EAAE,UAAU,EACnB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,GAAG,KAAK,EACvB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM;IAGrB,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC;YAqB5B,MAAM;CAgBrB"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Sends a series of Content-Range requests to an URL.
5
+ * - The stream size is unknown in advance even theoretically. So we read it
6
+ * with chunkSize+1 bytes chunks (+1 is to know for sure, is there something
7
+ * else left in the stream or not) and then send data with chunkSize bytes
8
+ * chunks.
9
+ * - The last chunk is a terminating one (and we know, which one is the last),
10
+ * so we reflect it in "Content-Range: x-y/S" format setting S to the total
11
+ * number of bytes in the stream.
12
+ */
13
+ class RestRangeUploader {
14
+ constructor(_client, _chunkSize, _method, _path, _mimeType) {
15
+ this._client = _client;
16
+ this._chunkSize = _chunkSize;
17
+ this._method = _method;
18
+ this._path = _path;
19
+ this._mimeType = _mimeType;
20
+ this._pos = 0;
21
+ }
22
+ async upload(stream) {
23
+ let buf = Buffer.allocUnsafe(0);
24
+ let res = null;
25
+ for await (const readData of stream) {
26
+ buf = Buffer.concat([buf, readData]);
27
+ while (buf.length >= this._chunkSize + 1) {
28
+ res = await this._flush(buf.slice(0, this._chunkSize), false);
29
+ buf = Buffer.from(buf.slice(this._chunkSize));
30
+ }
31
+ // After this `while` loop finishes, there is always something left in buf
32
+ // (due to the +1 trick). It guarantees that we have a chance to call
33
+ // flush(..., true) for the very last chunk.
34
+ }
35
+ if (buf.length > 0) {
36
+ res = await this._flush(buf, true);
37
+ }
38
+ return res;
39
+ }
40
+ async _flush(buf, isLast) {
41
+ if (buf.length === 0) {
42
+ return null;
43
+ }
44
+ const totalSize = isLast ? this._pos + buf.length : "*";
45
+ const res = await this._client
46
+ .writeRaw(this._path, buf, this._mimeType, this._method, "*/*")
47
+ .setHeader("Content-Range", `bytes ${this._pos}-${this._pos + buf.length - 1}/${totalSize}`)
48
+ .text();
49
+ this._pos += buf.length;
50
+ return res;
51
+ }
52
+ }
53
+ exports.default = RestRangeUploader;
54
+ //# sourceMappingURL=RestRangeUploader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RestRangeUploader.js","sourceRoot":"","sources":["../../src/internal/RestRangeUploader.ts"],"names":[],"mappings":";;AAEA;;;;;;;;;GASG;AACH,MAAqB,iBAAiB;IAGpC,YACU,OAAmB,EAC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AAC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC;QACxD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,OAAO;aAC3B,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC;aAC9D,SAAS,CACR,eAAe,EACf,SAAS,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,SAAS,EAAE,CAChE;aACA,IAAI,EAAE,CAAC;QACV,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,MAAM,CAAC;QACxB,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AAhDD,oCAgDC"}
@@ -0,0 +1,8 @@
1
+ import type RestOptions from "../RestOptions";
2
+ import type RestResponse from "../RestResponse";
3
+ /**
4
+ * Returns a new retry delay of the error needs to be retried, otherwise
5
+ * "no_retry".
6
+ */
7
+ export default function calcRetryDelay(error: any, options: RestOptions, res: RestResponse, retryDelayMs: number): number | "no_retry";
8
+ //# sourceMappingURL=calcRetryDelay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calcRetryDelay.d.ts","sourceRoot":"","sources":["../../src/internal/calcRetryDelay.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,WAAW,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,YAAY,MAAM,iBAAiB,CAAC;AAEhD;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CACpC,KAAK,EAAE,GAAG,EACV,OAAO,EAAE,WAAW,EACpB,GAAG,EAAE,YAAY,EACjB,YAAY,EAAE,MAAM,GACnB,MAAM,GAAG,UAAU,CA0CrB"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const RestContentSizeOverLimitError_1 = __importDefault(require("../errors/RestContentSizeOverLimitError"));
7
+ const RestRateLimitError_1 = __importDefault(require("../errors/RestRateLimitError"));
8
+ const RestRetriableError_1 = __importDefault(require("../errors/RestRetriableError"));
9
+ const RestTokenInvalidError_1 = __importDefault(require("../errors/RestTokenInvalidError"));
10
+ /**
11
+ * Returns a new retry delay of the error needs to be retried, otherwise
12
+ * "no_retry".
13
+ */
14
+ function calcRetryDelay(error, options, res, retryDelayMs) {
15
+ if (error instanceof RestRateLimitError_1.default ||
16
+ error instanceof RestRetriableError_1.default) {
17
+ // We've already made a decision to retry this error.
18
+ return Math.min(options.retryDelayMaxMs, Math.max(retryDelayMs, error.delayMs));
19
+ }
20
+ switch (options.isRetriableError(res, error)) {
21
+ case "RETRY":
22
+ default:
23
+ break; // number returned
24
+ case "BEST_EFFORT":
25
+ if (error instanceof RestTokenInvalidError_1.default) {
26
+ return "no_retry";
27
+ }
28
+ if (!(error instanceof RestRateLimitError_1.default) &&
29
+ res.status >= 400 &&
30
+ res.status <= 499) {
31
+ return "no_retry";
32
+ }
33
+ if (error instanceof RestContentSizeOverLimitError_1.default) {
34
+ // Content size ... over limit.
35
+ return "no_retry";
36
+ }
37
+ break;
38
+ case "NEVER_RETRY":
39
+ return "no_retry";
40
+ }
41
+ return retryDelayMs;
42
+ }
43
+ exports.default = calcRetryDelay;
44
+ //# sourceMappingURL=calcRetryDelay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calcRetryDelay.js","sourceRoot":"","sources":["../../src/internal/calcRetryDelay.ts"],"names":[],"mappings":";;;;;AAAA,4GAAoF;AACpF,sFAA8D;AAC9D,sFAA8D;AAC9D,4FAAoE;AAIpE;;;GAGG;AACH,SAAwB,cAAc,CACpC,KAAU,EACV,OAAoB,EACpB,GAAiB,EACjB,YAAoB;IAEpB,IACE,KAAK,YAAY,4BAAkB;QACnC,KAAK,YAAY,4BAAkB,EACnC;QACA,qDAAqD;QACrD,OAAO,IAAI,CAAC,GAAG,CACb,OAAO,CAAC,eAAe,EACvB,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,CACtC,CAAC;KACH;IAED,QAAQ,OAAO,CAAC,gBAAgB,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE;QAC5C,KAAK,OAAO,CAAC;QACb;YACE,MAAM,CAAC,kBAAkB;QAE3B,KAAK,aAAa;YAChB,IAAI,KAAK,YAAY,+BAAqB,EAAE;gBAC1C,OAAO,UAAU,CAAC;aACnB;YAED,IACE,CAAC,CAAC,KAAK,YAAY,4BAAkB,CAAC;gBACtC,GAAG,CAAC,MAAM,IAAI,GAAG;gBACjB,GAAG,CAAC,MAAM,IAAI,GAAG,EACjB;gBACA,OAAO,UAAU,CAAC;aACnB;YAED,IAAI,KAAK,YAAY,uCAA6B,EAAE;gBAClD,+BAA+B;gBAC/B,OAAO,UAAU,CAAC;aACnB;YAED,MAAM;QAER,KAAK,aAAa;YAChB,OAAO,UAAU,CAAC;KACrB;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AA/CD,iCA+CC"}
@@ -0,0 +1,6 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ export default function inspectPossibleJSON(headers: {
4
+ get(name: string): string | null;
5
+ }, text: string | Buffer | NodeJS.ReadableStream, maxOutputLen: number): string;
6
+ //# sourceMappingURL=inspectPossibleJSON.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inspectPossibleJSON.d.ts","sourceRoot":"","sources":["../../src/internal/inspectPossibleJSON.ts"],"names":[],"mappings":";;AAIA,MAAM,CAAC,OAAO,UAAU,mBAAmB,CACzC,OAAO,EAAE;IAAE,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;CAAE,EAC7C,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,cAAc,EAC7C,YAAY,EAAE,MAAM,GACnB,MAAM,CAuCR"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const util_1 = require("util");
7
+ const sortBy_1 = __importDefault(require("lodash/sortBy"));
8
+ const truncate_1 = __importDefault(require("lodash/truncate"));
9
+ function inspectPossibleJSON(headers, text, maxOutputLen) {
10
+ const MAX_LEN_TO_TRY_PARSE = 1024 * 1024;
11
+ if (typeof text === "string" && text.length > MAX_LEN_TO_TRY_PARSE) {
12
+ // Don't even try to JSON-parse if the text is too long.
13
+ return ellipsis(text, maxOutputLen);
14
+ }
15
+ if (text instanceof Buffer) {
16
+ return `<Buffer: ${text.length} bytes>`;
17
+ }
18
+ if (!text || typeof text === "string") {
19
+ if (!(headers.get("content-type") || "").match(/json/)) {
20
+ return ellipsis(text, maxOutputLen);
21
+ }
22
+ try {
23
+ const json = JSON.parse(text);
24
+ if (json && typeof json === "object" && !(json instanceof Array)) {
25
+ // Move error/errors fields on top for better logging. This is a poor
26
+ // man's approach: of course not all APIs return error/errors fields at
27
+ // all, but it's hard to reorder at any other layer of abstraction.
28
+ reorderObjectProps(json, (k) => k === "error" || k === "errors" ? "" : k);
29
+ }
30
+ return ellipsis((0, util_1.inspect)(json, { depth: 20, compact: true }), maxOutputLen);
31
+ }
32
+ catch (e) {
33
+ return ellipsis(text, maxOutputLen);
34
+ }
35
+ }
36
+ return "<Stream>";
37
+ }
38
+ exports.default = inspectPossibleJSON;
39
+ /**
40
+ * In-place-reorders keys in a given object. The important part is to do it
41
+ * in-place to e.g. be able to alter some @Memoized values.
42
+ */
43
+ function reorderObjectProps(obj, ranker) {
44
+ const entries = Object.entries(obj);
45
+ for (const k in obj) {
46
+ delete obj[k];
47
+ }
48
+ Object.assign(obj, Object.fromEntries((0, sortBy_1.default)(entries, ([k, v]) => ranker(k, v))));
49
+ }
50
+ function ellipsis(text, length) {
51
+ return (0, truncate_1.default)("" + text, { length }).trimEnd();
52
+ }
53
+ //# sourceMappingURL=inspectPossibleJSON.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inspectPossibleJSON.js","sourceRoot":"","sources":["../../src/internal/inspectPossibleJSON.ts"],"names":[],"mappings":";;;;;AAAA,+BAA+B;AAC/B,2DAAmC;AACnC,+DAAuC;AAEvC,SAAwB,mBAAmB,CACzC,OAA6C,EAC7C,IAA6C,EAC7C,YAAoB;IAEpB,MAAM,oBAAoB,GAAG,IAAI,GAAG,IAAI,CAAC;IAEzC,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,GAAG,oBAAoB,EAAE;QAClE,wDAAwD;QACxD,OAAO,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;KACrC;IAED,IAAI,IAAI,YAAY,MAAM,EAAE;QAC1B,OAAO,YAAY,IAAI,CAAC,MAAM,SAAS,CAAC;KACzC;IAED,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QACrC,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;YACtD,OAAO,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;SACrC;QAED,IAAI;YACF,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAE9B,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,YAAY,KAAK,CAAC,EAAE;gBAChE,qEAAqE;gBACrE,uEAAuE;gBACvE,mEAAmE;gBACnE,kBAAkB,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAC7B,CAAC,KAAK,OAAO,IAAI,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CACzC,CAAC;aACH;YAED,OAAO,QAAQ,CACb,IAAA,cAAO,EAAC,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,EAC3C,YAAY,CACb,CAAC;SACH;QAAC,OAAO,CAAM,EAAE;YACf,OAAO,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;SACrC;KACF;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AA3CD,sCA2CC;AAED;;;GAGG;AACH,SAAS,kBAAkB,CACzB,GAAwB,EACxB,MAA8C;IAE9C,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACpC,KAAK,MAAM,CAAC,IAAI,GAAG,EAAE;QACnB,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC;KACf;IAED,MAAM,CAAC,MAAM,CACX,GAAG,EACH,MAAM,CAAC,WAAW,CAAC,IAAA,gBAAM,EAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAC9D,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,IAAS,EAAE,MAAc;IACzC,OAAO,IAAA,kBAAQ,EAAC,EAAE,GAAG,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;AACnD,CAAC"}
@@ -0,0 +1,2 @@
1
+ export default function prependNewlineIfMultiline(str: string): string;
2
+ //# sourceMappingURL=prependNewlineIfMultiline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prependNewlineIfMultiline.d.ts","sourceRoot":"","sources":["../../src/internal/prependNewlineIfMultiline.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAAC,GAAG,EAAE,MAAM,UAE5D"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function prependNewlineIfMultiline(str) {
4
+ return str.trim().includes("\n") ? "\n" + str : str;
5
+ }
6
+ exports.default = prependNewlineIfMultiline;
7
+ //# sourceMappingURL=prependNewlineIfMultiline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prependNewlineIfMultiline.js","sourceRoot":"","sources":["../../src/internal/prependNewlineIfMultiline.ts"],"names":[],"mappings":";;AAAA,SAAwB,yBAAyB,CAAC,GAAW;IAC3D,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;AACtD,CAAC;AAFD,4CAEC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Allows to use URLs like /some/:abc/other and pass { abc: "xyz" } as one of
3
+ * body parameters. Such body parameters will be excluded from the body before
4
+ * sending the request (so they're "moved" into the URL).
5
+ */
6
+ export default function substituteParams<TBody>(url: string, body: TBody): [string, TBody];
7
+ //# sourceMappingURL=substituteParams.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"substituteParams.d.ts","sourceRoot":"","sources":["../../src/internal/substituteParams.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,KAAK,EAC5C,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,KAAK,GACV,CAAC,MAAM,EAAE,KAAK,CAAC,CAgBjB"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Allows to use URLs like /some/:abc/other and pass { abc: "xyz" } as one of
5
+ * body parameters. Such body parameters will be excluded from the body before
6
+ * sending the request (so they're "moved" into the URL).
7
+ */
8
+ function substituteParams(url, body) {
9
+ if (!body || typeof body !== "object") {
10
+ return [url, body];
11
+ }
12
+ url = url.replace(/:([a-z0-9_]+)/gi, (match, param) => {
13
+ const value = body[param];
14
+ if (typeof value === "string" || typeof value === "number") {
15
+ body = { ...body };
16
+ delete body[param];
17
+ return encodeURIComponent(value);
18
+ }
19
+ return match;
20
+ });
21
+ return [url, body];
22
+ }
23
+ exports.default = substituteParams;
24
+ //# sourceMappingURL=substituteParams.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"substituteParams.js","sourceRoot":"","sources":["../../src/internal/substituteParams.ts"],"names":[],"mappings":";;AAAA;;;;GAIG;AACH,SAAwB,gBAAgB,CACtC,GAAW,EACX,IAAW;IAEX,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QACrC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;KACpB;IAED,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QACpD,MAAM,KAAK,GAAI,IAAY,CAAC,KAAK,CAAC,CAAC;QACnC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC1D,IAAI,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC;YACnB,OAAQ,IAAY,CAAC,KAAK,CAAC,CAAC;YAC5B,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC;SAClC;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AACrB,CAAC;AAnBD,mCAmBC"}
@@ -0,0 +1,11 @@
1
+ import type RestOptions from "../RestOptions";
2
+ import type RestResponse from "../RestResponse";
3
+ /**
4
+ * The general idea is that we turn all logical errors into exceptions and then
5
+ * deal with exceptions only. I.e. throwing an exception becomes an internal API
6
+ * convention for errors. This is because fetch() throws its own exceptions, and
7
+ * also there may be some exceptions during validation of the response, or
8
+ * inside a middleware etc.
9
+ */
10
+ export default function throwIfErrorResponse(options: RestOptions, res: RestResponse): void;
11
+ //# sourceMappingURL=throwIfErrorResponse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"throwIfErrorResponse.d.ts","sourceRoot":"","sources":["../../src/internal/throwIfErrorResponse.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,WAAW,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,YAAY,MAAM,iBAAiB,CAAC;AAIhD;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAC1C,OAAO,EAAE,WAAW,EACpB,GAAG,EAAE,YAAY,QAsElB"}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const RestRateLimitError_1 = __importDefault(require("../errors/RestRateLimitError"));
7
+ const RestResponseError_1 = __importDefault(require("../errors/RestResponseError"));
8
+ const RestRetriableError_1 = __importDefault(require("../errors/RestRetriableError"));
9
+ const RestTokenInvalidError_1 = __importDefault(require("../errors/RestTokenInvalidError"));
10
+ const STATUS_TOO_MANY_REQUESTS = 429;
11
+ /**
12
+ * The general idea is that we turn all logical errors into exceptions and then
13
+ * deal with exceptions only. I.e. throwing an exception becomes an internal API
14
+ * convention for errors. This is because fetch() throws its own exceptions, and
15
+ * also there may be some exceptions during validation of the response, or
16
+ * inside a middleware etc.
17
+ */
18
+ function throwIfErrorResponse(options, res) {
19
+ const isSuccessResponse = options.isSuccessResponse(res);
20
+ if (isSuccessResponse === "SUCCESS") {
21
+ return;
22
+ }
23
+ const rateLimitDelayMs = options.isRateLimitError(res);
24
+ switch (rateLimitDelayMs) {
25
+ case "RATE_LIMIT":
26
+ throw new RestRateLimitError_1.default(`isRateLimitError() returned ${rateLimitDelayMs}`, 0, res);
27
+ case "BEST_EFFORT":
28
+ if (res.status === STATUS_TOO_MANY_REQUESTS) {
29
+ const retryAfterHeader = res.headers.get("Retry-After") || "0";
30
+ throw new RestRateLimitError_1.default(`Rate limited by HTTP status ${STATUS_TOO_MANY_REQUESTS}`, parseInt(retryAfterHeader) || 0, res);
31
+ }
32
+ break;
33
+ case "SOMETHING_ELSE":
34
+ break;
35
+ default:
36
+ throw new RestRateLimitError_1.default(`isRateLimitError() returned retry delay ${rateLimitDelayMs} ms`, rateLimitDelayMs, res);
37
+ }
38
+ const isTokenInvalidError = options.isTokenInvalidError(res);
39
+ if (isTokenInvalidError) {
40
+ throw new RestTokenInvalidError_1.default("Invalid app token", res);
41
+ }
42
+ const retryDelayMs = options.isRetriableError(res, null);
43
+ switch (retryDelayMs) {
44
+ case "RETRY":
45
+ throw new RestRetriableError_1.default(`isRetriableError() returned ${retryDelayMs}`, 0, res);
46
+ case "BEST_EFFORT":
47
+ case "NEVER_RETRY":
48
+ break;
49
+ default:
50
+ throw new RestRetriableError_1.default(`"isRetriableError() returned retry delay ${retryDelayMs} ms`, retryDelayMs, res);
51
+ }
52
+ if (isSuccessResponse === "THROW") {
53
+ throw new RestResponseError_1.default(`isSuccessResponse() returned ${isSuccessResponse}`, res);
54
+ }
55
+ if (res.status >= 300) {
56
+ throw new RestResponseError_1.default("", res);
57
+ }
58
+ }
59
+ exports.default = throwIfErrorResponse;
60
+ //# sourceMappingURL=throwIfErrorResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"throwIfErrorResponse.js","sourceRoot":"","sources":["../../src/internal/throwIfErrorResponse.ts"],"names":[],"mappings":";;;;;AAAA,sFAA8D;AAC9D,oFAA4D;AAC5D,sFAA8D;AAC9D,4FAAoE;AAIpE,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAErC;;;;;;GAMG;AACH,SAAwB,oBAAoB,CAC1C,OAAoB,EACpB,GAAiB;IAEjB,MAAM,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;IACzD,IAAI,iBAAiB,KAAK,SAAS,EAAE;QACnC,OAAO;KACR;IAED,MAAM,gBAAgB,GAAG,OAAO,CAA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