@bigbinary/neeto-payments-frontend 1.6.0-beta2 → 2.0.1

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 (106) hide show
  1. package/dist/AccountsDashboard.js +8 -10
  2. package/dist/AccountsDashboard.js.map +1 -1
  3. package/dist/Dashboard.js +11 -11
  4. package/dist/{ExportModal-85725c35.js → ExportModal-48434e79.js} +8 -8
  5. package/dist/{ExportModal-85725c35.js.map → ExportModal-48434e79.js.map} +1 -1
  6. package/dist/PayoutsDashboard.js +10 -12
  7. package/dist/PayoutsDashboard.js.map +1 -1
  8. package/dist/PayoutsPage.js +11 -11
  9. package/dist/RazorpayDashboard.js +9 -11
  10. package/dist/RazorpayDashboard.js.map +1 -1
  11. package/dist/RazorpayPaymentButton.js +6 -9
  12. package/dist/RazorpayPaymentButton.js.map +1 -1
  13. package/dist/StripeConnect.js +5 -6
  14. package/dist/StripeConnect.js.map +1 -1
  15. package/dist/UpiMarkAsPaidButton.js +4 -7
  16. package/dist/UpiMarkAsPaidButton.js.map +1 -1
  17. package/dist/UpiPayment.js +2 -5
  18. package/dist/UpiPayment.js.map +1 -1
  19. package/dist/V2PaymentsDashboard.js +5 -6
  20. package/dist/V2PaymentsDashboard.js.map +1 -1
  21. package/dist/cjs/AccountsDashboard.js +11 -12
  22. package/dist/cjs/AccountsDashboard.js.map +1 -1
  23. package/dist/cjs/Dashboard.js +15 -13
  24. package/dist/cjs/Dashboard.js.map +1 -1
  25. package/dist/cjs/{ExportModal-20f368a1.js → ExportModal-edfd3a7f.js} +11 -10
  26. package/dist/cjs/{ExportModal-20f368a1.js.map → ExportModal-edfd3a7f.js.map} +1 -1
  27. package/dist/cjs/PayoutsDashboard.js +12 -13
  28. package/dist/cjs/PayoutsDashboard.js.map +1 -1
  29. package/dist/cjs/PayoutsPage.js +11 -11
  30. package/dist/cjs/RazorpayDashboard.js +10 -12
  31. package/dist/cjs/RazorpayDashboard.js.map +1 -1
  32. package/dist/cjs/RazorpayPaymentButton.js +6 -9
  33. package/dist/cjs/RazorpayPaymentButton.js.map +1 -1
  34. package/dist/cjs/StripeConnect.js +6 -7
  35. package/dist/cjs/StripeConnect.js.map +1 -1
  36. package/dist/cjs/UpiMarkAsPaidButton.js +4 -7
  37. package/dist/cjs/UpiMarkAsPaidButton.js.map +1 -1
  38. package/dist/cjs/UpiPayment.js +2 -5
  39. package/dist/cjs/UpiPayment.js.map +1 -1
  40. package/dist/cjs/V2PaymentsDashboard.js +6 -7
  41. package/dist/cjs/V2PaymentsDashboard.js.map +1 -1
  42. package/dist/cjs/{exportChannel-7bd80952.js → exportChannel-9ac7cd08.js} +3 -3
  43. package/dist/cjs/{exportChannel-7bd80952.js.map → exportChannel-9ac7cd08.js.map} +1 -1
  44. package/dist/cjs/index.js +14 -14
  45. package/dist/cjs/queryConstants-45f84f3e.js +23 -0
  46. package/dist/cjs/queryConstants-45f84f3e.js.map +1 -0
  47. package/dist/cjs/renderFunctions-ec0f0a22.js +167 -0
  48. package/dist/cjs/renderFunctions-ec0f0a22.js.map +1 -0
  49. package/dist/cjs/{useConnectApi-f0665633.js → useConnectApi-c4afdf7d.js} +9 -8
  50. package/dist/cjs/useConnectApi-c4afdf7d.js.map +1 -0
  51. package/dist/cjs/{useFiltersAndPagination-312c0331.js → useFiltersAndPagination-0a176991.js} +2 -2
  52. package/dist/cjs/{useFiltersAndPagination-312c0331.js.map → useFiltersAndPagination-0a176991.js.map} +1 -1
  53. package/dist/cjs/{usePaymentApi-ae70e5df.js → usePaymentApi-7e79121a.js} +5 -5
  54. package/dist/cjs/{usePaymentApi-ae70e5df.js.map → usePaymentApi-7e79121a.js.map} +1 -1
  55. package/dist/cjs/{usePaymentsApi-815be3da.js → usePaymentsApi-74c8e44e.js} +4 -4
  56. package/dist/cjs/{usePaymentsApi-815be3da.js.map → usePaymentsApi-74c8e44e.js.map} +1 -1
  57. package/dist/cjs/{usePlatformApi-830827fa.js → usePlatformApi-cbedf69d.js} +11 -10
  58. package/dist/cjs/{usePlatformApi-830827fa.js.map → usePlatformApi-cbedf69d.js.map} +1 -1
  59. package/dist/cjs/useRazorpayPayment.js +3 -7
  60. package/dist/cjs/useRazorpayPayment.js.map +1 -1
  61. package/dist/{exportChannel-250e6f14.js → exportChannel-d0b7ed09.js} +2 -2
  62. package/dist/{exportChannel-250e6f14.js.map → exportChannel-d0b7ed09.js.map} +1 -1
  63. package/dist/index.js +14 -14
  64. package/dist/queryConstants-7d91832f.js +21 -0
  65. package/dist/queryConstants-7d91832f.js.map +1 -0
  66. package/dist/renderFunctions-058c9e2b.js +147 -0
  67. package/dist/renderFunctions-058c9e2b.js.map +1 -0
  68. package/dist/{useConnectApi-87335bf6.js → useConnectApi-4009b9b5.js} +3 -2
  69. package/dist/useConnectApi-4009b9b5.js.map +1 -0
  70. package/dist/{useFiltersAndPagination-2ab7bc8f.js → useFiltersAndPagination-bc8bad69.js} +2 -2
  71. package/dist/{useFiltersAndPagination-2ab7bc8f.js.map → useFiltersAndPagination-bc8bad69.js.map} +1 -1
  72. package/dist/{usePaymentApi-12737871.js → usePaymentApi-9876df31.js} +3 -3
  73. package/dist/{usePaymentApi-12737871.js.map → usePaymentApi-9876df31.js.map} +1 -1
  74. package/dist/{usePaymentsApi-a801ab15.js → usePaymentsApi-f3be0081.js} +2 -2
  75. package/dist/{usePaymentsApi-a801ab15.js.map → usePaymentsApi-f3be0081.js.map} +1 -1
  76. package/dist/{usePlatformApi-8adc2a50.js → usePlatformApi-b6664fae.js} +4 -3
  77. package/dist/{usePlatformApi-8adc2a50.js.map → usePlatformApi-b6664fae.js.map} +1 -1
  78. package/dist/useRazorpayPayment.js +3 -7
  79. package/dist/useRazorpayPayment.js.map +1 -1
  80. package/package.json +12 -10
  81. package/dist/U2TDTBMY-c464dc98.js +0 -12081
  82. package/dist/U2TDTBMY-c464dc98.js.map +0 -1
  83. package/dist/cjs/U2TDTBMY-e2fad970.js +0 -12083
  84. package/dist/cjs/U2TDTBMY-e2fad970.js.map +0 -1
  85. package/dist/cjs/mutation-ed7b84fc.js +0 -235
  86. package/dist/cjs/mutation-ed7b84fc.js.map +0 -1
  87. package/dist/cjs/queryConstants-de21eed5.js +0 -944
  88. package/dist/cjs/queryConstants-de21eed5.js.map +0 -1
  89. package/dist/cjs/renderFunctions-398d3fb5.js +0 -3719
  90. package/dist/cjs/renderFunctions-398d3fb5.js.map +0 -1
  91. package/dist/cjs/useConnectApi-f0665633.js.map +0 -1
  92. package/dist/cjs/useMutation-4c7cdbe1.js +0 -154
  93. package/dist/cjs/useMutation-4c7cdbe1.js.map +0 -1
  94. package/dist/cjs/utils-7eba34a4.js +0 -664
  95. package/dist/cjs/utils-7eba34a4.js.map +0 -1
  96. package/dist/mutation-286611ef.js +0 -232
  97. package/dist/mutation-286611ef.js.map +0 -1
  98. package/dist/queryConstants-765c8816.js +0 -920
  99. package/dist/queryConstants-765c8816.js.map +0 -1
  100. package/dist/renderFunctions-97b121a4.js +0 -3633
  101. package/dist/renderFunctions-97b121a4.js.map +0 -1
  102. package/dist/useConnectApi-87335bf6.js.map +0 -1
  103. package/dist/useMutation-8d67f853.js +0 -132
  104. package/dist/useMutation-8d67f853.js.map +0 -1
  105. package/dist/utils-e29db9c9.js +0 -614
  106. package/dist/utils-e29db9c9.js.map +0 -1
@@ -1,944 +0,0 @@
1
- 'use strict';
2
-
3
- var utils = require('./utils-7eba34a4.js');
4
- var React = require('react');
5
- require('react/jsx-runtime');
6
-
7
- function _interopNamespace(e) {
8
- if (e && e.__esModule) return e;
9
- var n = Object.create(null);
10
- if (e) {
11
- Object.keys(e).forEach(function (k) {
12
- if (k !== 'default') {
13
- var d = Object.getOwnPropertyDescriptor(e, k);
14
- Object.defineProperty(n, k, d.get ? d : {
15
- enumerable: true,
16
- get: function () { return e[k]; }
17
- });
18
- }
19
- });
20
- }
21
- n["default"] = e;
22
- return Object.freeze(n);
23
- }
24
-
25
- var React__namespace = /*#__PURE__*/_interopNamespace(React);
26
-
27
- // src/query.ts
28
- var Query = class extends utils.Removable {
29
- #initialState;
30
- #revertState;
31
- #cache;
32
- #retryer;
33
- #defaultOptions;
34
- #abortSignalConsumed;
35
- constructor(config) {
36
- super();
37
- this.#abortSignalConsumed = false;
38
- this.#defaultOptions = config.defaultOptions;
39
- this.setOptions(config.options);
40
- this.observers = [];
41
- this.#cache = config.cache;
42
- this.queryKey = config.queryKey;
43
- this.queryHash = config.queryHash;
44
- this.#initialState = config.state || getDefaultState(this.options);
45
- this.state = this.#initialState;
46
- this.scheduleGc();
47
- }
48
- get meta() {
49
- return this.options.meta;
50
- }
51
- get promise() {
52
- return this.#retryer?.promise;
53
- }
54
- setOptions(options) {
55
- this.options = { ...this.#defaultOptions, ...options };
56
- this.updateGcTime(this.options.gcTime);
57
- }
58
- optionalRemove() {
59
- if (!this.observers.length && this.state.fetchStatus === "idle") {
60
- this.#cache.remove(this);
61
- }
62
- }
63
- setData(newData, options) {
64
- const data = utils.replaceData(this.state.data, newData, this.options);
65
- this.#dispatch({
66
- data,
67
- type: "success",
68
- dataUpdatedAt: options?.updatedAt,
69
- manual: options?.manual
70
- });
71
- return data;
72
- }
73
- setState(state, setStateOptions) {
74
- this.#dispatch({ type: "setState", state, setStateOptions });
75
- }
76
- cancel(options) {
77
- const promise = this.#retryer?.promise;
78
- this.#retryer?.cancel(options);
79
- return promise ? promise.then(utils.noop).catch(utils.noop) : Promise.resolve();
80
- }
81
- destroy() {
82
- super.destroy();
83
- this.cancel({ silent: true });
84
- }
85
- reset() {
86
- this.destroy();
87
- this.setState(this.#initialState);
88
- }
89
- isActive() {
90
- return this.observers.some((observer) => observer.options.enabled !== false);
91
- }
92
- isDisabled() {
93
- return this.getObserversCount() > 0 && !this.isActive();
94
- }
95
- isStale() {
96
- if (this.state.isInvalidated) {
97
- return true;
98
- }
99
- if (this.getObserversCount() > 0) {
100
- return this.observers.some(
101
- (observer) => observer.getCurrentResult().isStale
102
- );
103
- }
104
- return this.state.data === void 0;
105
- }
106
- isStaleByTime(staleTime = 0) {
107
- return this.state.isInvalidated || this.state.data === void 0 || !utils.timeUntilStale(this.state.dataUpdatedAt, staleTime);
108
- }
109
- onFocus() {
110
- const observer = this.observers.find((x) => x.shouldFetchOnWindowFocus());
111
- observer?.refetch({ cancelRefetch: false });
112
- this.#retryer?.continue();
113
- }
114
- onOnline() {
115
- const observer = this.observers.find((x) => x.shouldFetchOnReconnect());
116
- observer?.refetch({ cancelRefetch: false });
117
- this.#retryer?.continue();
118
- }
119
- addObserver(observer) {
120
- if (!this.observers.includes(observer)) {
121
- this.observers.push(observer);
122
- this.clearGcTimeout();
123
- this.#cache.notify({ type: "observerAdded", query: this, observer });
124
- }
125
- }
126
- removeObserver(observer) {
127
- if (this.observers.includes(observer)) {
128
- this.observers = this.observers.filter((x) => x !== observer);
129
- if (!this.observers.length) {
130
- if (this.#retryer) {
131
- if (this.#abortSignalConsumed) {
132
- this.#retryer.cancel({ revert: true });
133
- } else {
134
- this.#retryer.cancelRetry();
135
- }
136
- }
137
- this.scheduleGc();
138
- }
139
- this.#cache.notify({ type: "observerRemoved", query: this, observer });
140
- }
141
- }
142
- getObserversCount() {
143
- return this.observers.length;
144
- }
145
- invalidate() {
146
- if (!this.state.isInvalidated) {
147
- this.#dispatch({ type: "invalidate" });
148
- }
149
- }
150
- fetch(options, fetchOptions) {
151
- if (this.state.fetchStatus !== "idle") {
152
- if (this.state.data !== void 0 && fetchOptions?.cancelRefetch) {
153
- this.cancel({ silent: true });
154
- } else if (this.#retryer) {
155
- this.#retryer.continueRetry();
156
- return this.#retryer.promise;
157
- }
158
- }
159
- if (options) {
160
- this.setOptions(options);
161
- }
162
- if (!this.options.queryFn) {
163
- const observer = this.observers.find((x) => x.options.queryFn);
164
- if (observer) {
165
- this.setOptions(observer.options);
166
- }
167
- }
168
- if (process.env.NODE_ENV !== "production") {
169
- if (!Array.isArray(this.options.queryKey)) {
170
- console.error(
171
- `As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']`
172
- );
173
- }
174
- }
175
- const abortController = new AbortController();
176
- const addSignalProperty = (object) => {
177
- Object.defineProperty(object, "signal", {
178
- enumerable: true,
179
- get: () => {
180
- this.#abortSignalConsumed = true;
181
- return abortController.signal;
182
- }
183
- });
184
- };
185
- const fetchFn = () => {
186
- const queryFn = utils.ensureQueryFn(this.options, fetchOptions);
187
- const queryFnContext = {
188
- queryKey: this.queryKey,
189
- meta: this.meta
190
- };
191
- addSignalProperty(queryFnContext);
192
- this.#abortSignalConsumed = false;
193
- if (this.options.persister) {
194
- return this.options.persister(
195
- queryFn,
196
- queryFnContext,
197
- this
198
- );
199
- }
200
- return queryFn(queryFnContext);
201
- };
202
- const context = {
203
- fetchOptions,
204
- options: this.options,
205
- queryKey: this.queryKey,
206
- state: this.state,
207
- fetchFn
208
- };
209
- addSignalProperty(context);
210
- this.options.behavior?.onFetch(
211
- context,
212
- this
213
- );
214
- this.#revertState = this.state;
215
- if (this.state.fetchStatus === "idle" || this.state.fetchMeta !== context.fetchOptions?.meta) {
216
- this.#dispatch({ type: "fetch", meta: context.fetchOptions?.meta });
217
- }
218
- const onError = (error) => {
219
- if (!(utils.isCancelledError(error) && error.silent)) {
220
- this.#dispatch({
221
- type: "error",
222
- error
223
- });
224
- }
225
- if (!utils.isCancelledError(error)) {
226
- this.#cache.config.onError?.(
227
- error,
228
- this
229
- );
230
- this.#cache.config.onSettled?.(
231
- this.state.data,
232
- error,
233
- this
234
- );
235
- }
236
- if (!this.isFetchingOptimistic) {
237
- this.scheduleGc();
238
- }
239
- this.isFetchingOptimistic = false;
240
- };
241
- this.#retryer = utils.createRetryer({
242
- initialPromise: fetchOptions?.initialPromise,
243
- fn: context.fetchFn,
244
- abort: abortController.abort.bind(abortController),
245
- onSuccess: (data) => {
246
- if (data === void 0) {
247
- if (process.env.NODE_ENV !== "production") {
248
- console.error(
249
- `Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`
250
- );
251
- }
252
- onError(new Error(`${this.queryHash} data is undefined`));
253
- return;
254
- }
255
- this.setData(data);
256
- this.#cache.config.onSuccess?.(data, this);
257
- this.#cache.config.onSettled?.(
258
- data,
259
- this.state.error,
260
- this
261
- );
262
- if (!this.isFetchingOptimistic) {
263
- this.scheduleGc();
264
- }
265
- this.isFetchingOptimistic = false;
266
- },
267
- onError,
268
- onFail: (failureCount, error) => {
269
- this.#dispatch({ type: "failed", failureCount, error });
270
- },
271
- onPause: () => {
272
- this.#dispatch({ type: "pause" });
273
- },
274
- onContinue: () => {
275
- this.#dispatch({ type: "continue" });
276
- },
277
- retry: context.options.retry,
278
- retryDelay: context.options.retryDelay,
279
- networkMode: context.options.networkMode,
280
- canRun: () => true
281
- });
282
- return this.#retryer.start();
283
- }
284
- #dispatch(action) {
285
- const reducer = (state) => {
286
- switch (action.type) {
287
- case "failed":
288
- return {
289
- ...state,
290
- fetchFailureCount: action.failureCount,
291
- fetchFailureReason: action.error
292
- };
293
- case "pause":
294
- return {
295
- ...state,
296
- fetchStatus: "paused"
297
- };
298
- case "continue":
299
- return {
300
- ...state,
301
- fetchStatus: "fetching"
302
- };
303
- case "fetch":
304
- return {
305
- ...state,
306
- ...fetchState(state.data, this.options),
307
- fetchMeta: action.meta ?? null
308
- };
309
- case "success":
310
- return {
311
- ...state,
312
- data: action.data,
313
- dataUpdateCount: state.dataUpdateCount + 1,
314
- dataUpdatedAt: action.dataUpdatedAt ?? Date.now(),
315
- error: null,
316
- isInvalidated: false,
317
- status: "success",
318
- ...!action.manual && {
319
- fetchStatus: "idle",
320
- fetchFailureCount: 0,
321
- fetchFailureReason: null
322
- }
323
- };
324
- case "error":
325
- const error = action.error;
326
- if (utils.isCancelledError(error) && error.revert && this.#revertState) {
327
- return { ...this.#revertState, fetchStatus: "idle" };
328
- }
329
- return {
330
- ...state,
331
- error,
332
- errorUpdateCount: state.errorUpdateCount + 1,
333
- errorUpdatedAt: Date.now(),
334
- fetchFailureCount: state.fetchFailureCount + 1,
335
- fetchFailureReason: error,
336
- fetchStatus: "idle",
337
- status: "error"
338
- };
339
- case "invalidate":
340
- return {
341
- ...state,
342
- isInvalidated: true
343
- };
344
- case "setState":
345
- return {
346
- ...state,
347
- ...action.state
348
- };
349
- }
350
- };
351
- this.state = reducer(this.state);
352
- utils.notifyManager.batch(() => {
353
- this.observers.forEach((observer) => {
354
- observer.onQueryUpdate();
355
- });
356
- this.#cache.notify({ query: this, type: "updated", action });
357
- });
358
- }
359
- };
360
- function fetchState(data, options) {
361
- return {
362
- fetchFailureCount: 0,
363
- fetchFailureReason: null,
364
- fetchStatus: utils.canFetch(options.networkMode) ? "fetching" : "paused",
365
- ...data === void 0 && {
366
- error: null,
367
- status: "pending"
368
- }
369
- };
370
- }
371
- function getDefaultState(options) {
372
- const data = typeof options.initialData === "function" ? options.initialData() : options.initialData;
373
- const hasData = data !== void 0;
374
- const initialDataUpdatedAt = hasData ? typeof options.initialDataUpdatedAt === "function" ? options.initialDataUpdatedAt() : options.initialDataUpdatedAt : 0;
375
- return {
376
- data,
377
- dataUpdateCount: 0,
378
- dataUpdatedAt: hasData ? initialDataUpdatedAt ?? Date.now() : 0,
379
- error: null,
380
- errorUpdateCount: 0,
381
- errorUpdatedAt: 0,
382
- fetchFailureCount: 0,
383
- fetchFailureReason: null,
384
- fetchMeta: null,
385
- isInvalidated: false,
386
- status: hasData ? "success" : "pending",
387
- fetchStatus: "idle"
388
- };
389
- }
390
-
391
- // src/queryObserver.ts
392
- var QueryObserver = class extends utils.Subscribable {
393
- constructor(client, options) {
394
- super();
395
- this.options = options;
396
- this.#client = client;
397
- this.#selectError = null;
398
- this.bindMethods();
399
- this.setOptions(options);
400
- }
401
- #client;
402
- #currentQuery = void 0;
403
- #currentQueryInitialState = void 0;
404
- #currentResult = void 0;
405
- #currentResultState;
406
- #currentResultOptions;
407
- #selectError;
408
- #selectFn;
409
- #selectResult;
410
- // This property keeps track of the last query with defined data.
411
- // It will be used to pass the previous data and query to the placeholder function between renders.
412
- #lastQueryWithDefinedData;
413
- #staleTimeoutId;
414
- #refetchIntervalId;
415
- #currentRefetchInterval;
416
- #trackedProps = /* @__PURE__ */ new Set();
417
- bindMethods() {
418
- this.refetch = this.refetch.bind(this);
419
- }
420
- onSubscribe() {
421
- if (this.listeners.size === 1) {
422
- this.#currentQuery.addObserver(this);
423
- if (shouldFetchOnMount(this.#currentQuery, this.options)) {
424
- this.#executeFetch();
425
- } else {
426
- this.updateResult();
427
- }
428
- this.#updateTimers();
429
- }
430
- }
431
- onUnsubscribe() {
432
- if (!this.hasListeners()) {
433
- this.destroy();
434
- }
435
- }
436
- shouldFetchOnReconnect() {
437
- return shouldFetchOn(
438
- this.#currentQuery,
439
- this.options,
440
- this.options.refetchOnReconnect
441
- );
442
- }
443
- shouldFetchOnWindowFocus() {
444
- return shouldFetchOn(
445
- this.#currentQuery,
446
- this.options,
447
- this.options.refetchOnWindowFocus
448
- );
449
- }
450
- destroy() {
451
- this.listeners = /* @__PURE__ */ new Set();
452
- this.#clearStaleTimeout();
453
- this.#clearRefetchInterval();
454
- this.#currentQuery.removeObserver(this);
455
- }
456
- setOptions(options, notifyOptions) {
457
- const prevOptions = this.options;
458
- const prevQuery = this.#currentQuery;
459
- this.options = this.#client.defaultQueryOptions(options);
460
- if (this.options.enabled !== void 0 && typeof this.options.enabled !== "boolean") {
461
- throw new Error("Expected enabled to be a boolean");
462
- }
463
- this.#updateQuery();
464
- this.#currentQuery.setOptions(this.options);
465
- if (prevOptions._defaulted && !utils.shallowEqualObjects(this.options, prevOptions)) {
466
- this.#client.getQueryCache().notify({
467
- type: "observerOptionsUpdated",
468
- query: this.#currentQuery,
469
- observer: this
470
- });
471
- }
472
- const mounted = this.hasListeners();
473
- if (mounted && shouldFetchOptionally(
474
- this.#currentQuery,
475
- prevQuery,
476
- this.options,
477
- prevOptions
478
- )) {
479
- this.#executeFetch();
480
- }
481
- this.updateResult(notifyOptions);
482
- if (mounted && (this.#currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || this.options.staleTime !== prevOptions.staleTime)) {
483
- this.#updateStaleTimeout();
484
- }
485
- const nextRefetchInterval = this.#computeRefetchInterval();
486
- if (mounted && (this.#currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || nextRefetchInterval !== this.#currentRefetchInterval)) {
487
- this.#updateRefetchInterval(nextRefetchInterval);
488
- }
489
- }
490
- getOptimisticResult(options) {
491
- const query = this.#client.getQueryCache().build(this.#client, options);
492
- const result = this.createResult(query, options);
493
- if (shouldAssignObserverCurrentProperties(this, result)) {
494
- this.#currentResult = result;
495
- this.#currentResultOptions = this.options;
496
- this.#currentResultState = this.#currentQuery.state;
497
- }
498
- return result;
499
- }
500
- getCurrentResult() {
501
- return this.#currentResult;
502
- }
503
- trackResult(result, onPropTracked) {
504
- const trackedResult = {};
505
- Object.keys(result).forEach((key) => {
506
- Object.defineProperty(trackedResult, key, {
507
- configurable: false,
508
- enumerable: true,
509
- get: () => {
510
- this.trackProp(key);
511
- onPropTracked?.(key);
512
- return result[key];
513
- }
514
- });
515
- });
516
- return trackedResult;
517
- }
518
- trackProp(key) {
519
- this.#trackedProps.add(key);
520
- }
521
- getCurrentQuery() {
522
- return this.#currentQuery;
523
- }
524
- refetch({ ...options } = {}) {
525
- return this.fetch({
526
- ...options
527
- });
528
- }
529
- fetchOptimistic(options) {
530
- const defaultedOptions = this.#client.defaultQueryOptions(options);
531
- const query = this.#client.getQueryCache().build(this.#client, defaultedOptions);
532
- query.isFetchingOptimistic = true;
533
- return query.fetch().then(() => this.createResult(query, defaultedOptions));
534
- }
535
- fetch(fetchOptions) {
536
- return this.#executeFetch({
537
- ...fetchOptions,
538
- cancelRefetch: fetchOptions.cancelRefetch ?? true
539
- }).then(() => {
540
- this.updateResult();
541
- return this.#currentResult;
542
- });
543
- }
544
- #executeFetch(fetchOptions) {
545
- this.#updateQuery();
546
- let promise = this.#currentQuery.fetch(
547
- this.options,
548
- fetchOptions
549
- );
550
- if (!fetchOptions?.throwOnError) {
551
- promise = promise.catch(utils.noop);
552
- }
553
- return promise;
554
- }
555
- #updateStaleTimeout() {
556
- this.#clearStaleTimeout();
557
- if (utils.isServer || this.#currentResult.isStale || !utils.isValidTimeout(this.options.staleTime)) {
558
- return;
559
- }
560
- const time = utils.timeUntilStale(
561
- this.#currentResult.dataUpdatedAt,
562
- this.options.staleTime
563
- );
564
- const timeout = time + 1;
565
- this.#staleTimeoutId = setTimeout(() => {
566
- if (!this.#currentResult.isStale) {
567
- this.updateResult();
568
- }
569
- }, timeout);
570
- }
571
- #computeRefetchInterval() {
572
- return (typeof this.options.refetchInterval === "function" ? this.options.refetchInterval(this.#currentQuery) : this.options.refetchInterval) ?? false;
573
- }
574
- #updateRefetchInterval(nextInterval) {
575
- this.#clearRefetchInterval();
576
- this.#currentRefetchInterval = nextInterval;
577
- if (utils.isServer || this.options.enabled === false || !utils.isValidTimeout(this.#currentRefetchInterval) || this.#currentRefetchInterval === 0) {
578
- return;
579
- }
580
- this.#refetchIntervalId = setInterval(() => {
581
- if (this.options.refetchIntervalInBackground || utils.focusManager.isFocused()) {
582
- this.#executeFetch();
583
- }
584
- }, this.#currentRefetchInterval);
585
- }
586
- #updateTimers() {
587
- this.#updateStaleTimeout();
588
- this.#updateRefetchInterval(this.#computeRefetchInterval());
589
- }
590
- #clearStaleTimeout() {
591
- if (this.#staleTimeoutId) {
592
- clearTimeout(this.#staleTimeoutId);
593
- this.#staleTimeoutId = void 0;
594
- }
595
- }
596
- #clearRefetchInterval() {
597
- if (this.#refetchIntervalId) {
598
- clearInterval(this.#refetchIntervalId);
599
- this.#refetchIntervalId = void 0;
600
- }
601
- }
602
- createResult(query, options) {
603
- const prevQuery = this.#currentQuery;
604
- const prevOptions = this.options;
605
- const prevResult = this.#currentResult;
606
- const prevResultState = this.#currentResultState;
607
- const prevResultOptions = this.#currentResultOptions;
608
- const queryChange = query !== prevQuery;
609
- const queryInitialState = queryChange ? query.state : this.#currentQueryInitialState;
610
- const { state } = query;
611
- let newState = { ...state };
612
- let isPlaceholderData = false;
613
- let data;
614
- if (options._optimisticResults) {
615
- const mounted = this.hasListeners();
616
- const fetchOnMount = !mounted && shouldFetchOnMount(query, options);
617
- const fetchOptionally = mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions);
618
- if (fetchOnMount || fetchOptionally) {
619
- newState = {
620
- ...newState,
621
- ...fetchState(state.data, query.options)
622
- };
623
- }
624
- if (options._optimisticResults === "isRestoring") {
625
- newState.fetchStatus = "idle";
626
- }
627
- }
628
- let { error, errorUpdatedAt, status } = newState;
629
- if (options.select && newState.data !== void 0) {
630
- if (prevResult && newState.data === prevResultState?.data && options.select === this.#selectFn) {
631
- data = this.#selectResult;
632
- } else {
633
- try {
634
- this.#selectFn = options.select;
635
- data = options.select(newState.data);
636
- data = utils.replaceData(prevResult?.data, data, options);
637
- this.#selectResult = data;
638
- this.#selectError = null;
639
- } catch (selectError) {
640
- this.#selectError = selectError;
641
- }
642
- }
643
- } else {
644
- data = newState.data;
645
- }
646
- if (options.placeholderData !== void 0 && data === void 0 && status === "pending") {
647
- let placeholderData;
648
- if (prevResult?.isPlaceholderData && options.placeholderData === prevResultOptions?.placeholderData) {
649
- placeholderData = prevResult.data;
650
- } else {
651
- placeholderData = typeof options.placeholderData === "function" ? options.placeholderData(
652
- this.#lastQueryWithDefinedData?.state.data,
653
- this.#lastQueryWithDefinedData
654
- ) : options.placeholderData;
655
- if (options.select && placeholderData !== void 0) {
656
- try {
657
- placeholderData = options.select(placeholderData);
658
- this.#selectError = null;
659
- } catch (selectError) {
660
- this.#selectError = selectError;
661
- }
662
- }
663
- }
664
- if (placeholderData !== void 0) {
665
- status = "success";
666
- data = utils.replaceData(
667
- prevResult?.data,
668
- placeholderData,
669
- options
670
- );
671
- isPlaceholderData = true;
672
- }
673
- }
674
- if (this.#selectError) {
675
- error = this.#selectError;
676
- data = this.#selectResult;
677
- errorUpdatedAt = Date.now();
678
- status = "error";
679
- }
680
- const isFetching = newState.fetchStatus === "fetching";
681
- const isPending = status === "pending";
682
- const isError = status === "error";
683
- const isLoading = isPending && isFetching;
684
- const hasData = data !== void 0;
685
- const result = {
686
- status,
687
- fetchStatus: newState.fetchStatus,
688
- isPending,
689
- isSuccess: status === "success",
690
- isError,
691
- isInitialLoading: isLoading,
692
- isLoading,
693
- data,
694
- dataUpdatedAt: newState.dataUpdatedAt,
695
- error,
696
- errorUpdatedAt,
697
- failureCount: newState.fetchFailureCount,
698
- failureReason: newState.fetchFailureReason,
699
- errorUpdateCount: newState.errorUpdateCount,
700
- isFetched: newState.dataUpdateCount > 0 || newState.errorUpdateCount > 0,
701
- isFetchedAfterMount: newState.dataUpdateCount > queryInitialState.dataUpdateCount || newState.errorUpdateCount > queryInitialState.errorUpdateCount,
702
- isFetching,
703
- isRefetching: isFetching && !isPending,
704
- isLoadingError: isError && !hasData,
705
- isPaused: newState.fetchStatus === "paused",
706
- isPlaceholderData,
707
- isRefetchError: isError && hasData,
708
- isStale: isStale(query, options),
709
- refetch: this.refetch
710
- };
711
- return result;
712
- }
713
- updateResult(notifyOptions) {
714
- const prevResult = this.#currentResult;
715
- const nextResult = this.createResult(this.#currentQuery, this.options);
716
- this.#currentResultState = this.#currentQuery.state;
717
- this.#currentResultOptions = this.options;
718
- if (this.#currentResultState.data !== void 0) {
719
- this.#lastQueryWithDefinedData = this.#currentQuery;
720
- }
721
- if (utils.shallowEqualObjects(nextResult, prevResult)) {
722
- return;
723
- }
724
- this.#currentResult = nextResult;
725
- const defaultNotifyOptions = {};
726
- const shouldNotifyListeners = () => {
727
- if (!prevResult) {
728
- return true;
729
- }
730
- const { notifyOnChangeProps } = this.options;
731
- const notifyOnChangePropsValue = typeof notifyOnChangeProps === "function" ? notifyOnChangeProps() : notifyOnChangeProps;
732
- if (notifyOnChangePropsValue === "all" || !notifyOnChangePropsValue && !this.#trackedProps.size) {
733
- return true;
734
- }
735
- const includedProps = new Set(
736
- notifyOnChangePropsValue ?? this.#trackedProps
737
- );
738
- if (this.options.throwOnError) {
739
- includedProps.add("error");
740
- }
741
- return Object.keys(this.#currentResult).some((key) => {
742
- const typedKey = key;
743
- const changed = this.#currentResult[typedKey] !== prevResult[typedKey];
744
- return changed && includedProps.has(typedKey);
745
- });
746
- };
747
- if (notifyOptions?.listeners !== false && shouldNotifyListeners()) {
748
- defaultNotifyOptions.listeners = true;
749
- }
750
- this.#notify({ ...defaultNotifyOptions, ...notifyOptions });
751
- }
752
- #updateQuery() {
753
- const query = this.#client.getQueryCache().build(this.#client, this.options);
754
- if (query === this.#currentQuery) {
755
- return;
756
- }
757
- const prevQuery = this.#currentQuery;
758
- this.#currentQuery = query;
759
- this.#currentQueryInitialState = query.state;
760
- if (this.hasListeners()) {
761
- prevQuery?.removeObserver(this);
762
- query.addObserver(this);
763
- }
764
- }
765
- onQueryUpdate() {
766
- this.updateResult();
767
- if (this.hasListeners()) {
768
- this.#updateTimers();
769
- }
770
- }
771
- #notify(notifyOptions) {
772
- utils.notifyManager.batch(() => {
773
- if (notifyOptions.listeners) {
774
- this.listeners.forEach((listener) => {
775
- listener(this.#currentResult);
776
- });
777
- }
778
- this.#client.getQueryCache().notify({
779
- query: this.#currentQuery,
780
- type: "observerResultsUpdated"
781
- });
782
- });
783
- }
784
- };
785
- function shouldLoadOnMount(query, options) {
786
- return options.enabled !== false && query.state.data === void 0 && !(query.state.status === "error" && options.retryOnMount === false);
787
- }
788
- function shouldFetchOnMount(query, options) {
789
- return shouldLoadOnMount(query, options) || query.state.data !== void 0 && shouldFetchOn(query, options, options.refetchOnMount);
790
- }
791
- function shouldFetchOn(query, options, field) {
792
- if (options.enabled !== false) {
793
- const value = typeof field === "function" ? field(query) : field;
794
- return value === "always" || value !== false && isStale(query, options);
795
- }
796
- return false;
797
- }
798
- function shouldFetchOptionally(query, prevQuery, options, prevOptions) {
799
- return (query !== prevQuery || prevOptions.enabled === false) && (!options.suspense || query.state.status !== "error") && isStale(query, options);
800
- }
801
- function isStale(query, options) {
802
- return options.enabled !== false && query.isStaleByTime(options.staleTime);
803
- }
804
- function shouldAssignObserverCurrentProperties(observer, optimisticResult) {
805
- if (!utils.shallowEqualObjects(observer.getCurrentResult(), optimisticResult)) {
806
- return true;
807
- }
808
- return false;
809
- }
810
-
811
- var IsRestoringContext = React__namespace.createContext(false);
812
- var useIsRestoring = () => React__namespace.useContext(IsRestoringContext);
813
- IsRestoringContext.Provider;
814
-
815
- function createValue() {
816
- let isReset = false;
817
- return {
818
- clearReset: () => {
819
- isReset = false;
820
- },
821
- reset: () => {
822
- isReset = true;
823
- },
824
- isReset: () => {
825
- return isReset;
826
- }
827
- };
828
- }
829
- var QueryErrorResetBoundaryContext = React__namespace.createContext(createValue());
830
- var useQueryErrorResetBoundary = () => React__namespace.useContext(QueryErrorResetBoundaryContext);
831
-
832
- var ensurePreventErrorBoundaryRetry = (options, errorResetBoundary) => {
833
- if (options.suspense || options.throwOnError) {
834
- if (!errorResetBoundary.isReset()) {
835
- options.retryOnMount = false;
836
- }
837
- }
838
- };
839
- var useClearResetErrorBoundary = (errorResetBoundary) => {
840
- React__namespace.useEffect(() => {
841
- errorResetBoundary.clearReset();
842
- }, [errorResetBoundary]);
843
- };
844
- var getHasError = ({
845
- result,
846
- errorResetBoundary,
847
- throwOnError,
848
- query
849
- }) => {
850
- return result.isError && !errorResetBoundary.isReset() && !result.isFetching && query && utils.shouldThrowError(throwOnError, [result.error, query]);
851
- };
852
-
853
- // src/suspense.ts
854
- var ensureStaleTime = (defaultedOptions) => {
855
- if (defaultedOptions.suspense) {
856
- if (typeof defaultedOptions.staleTime !== "number") {
857
- defaultedOptions.staleTime = 1e3;
858
- }
859
- }
860
- };
861
- var shouldSuspend = (defaultedOptions, result) => defaultedOptions?.suspense && result.isPending;
862
- var fetchOptimistic = (defaultedOptions, observer, errorResetBoundary) => observer.fetchOptimistic(defaultedOptions).catch(() => {
863
- errorResetBoundary.clearReset();
864
- });
865
-
866
- function useBaseQuery(options, Observer, queryClient) {
867
- if (process.env.NODE_ENV !== "production") {
868
- if (typeof options !== "object" || Array.isArray(options)) {
869
- throw new Error(
870
- 'Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object'
871
- );
872
- }
873
- }
874
- const client = utils.useQueryClient(queryClient);
875
- const isRestoring = useIsRestoring();
876
- const errorResetBoundary = useQueryErrorResetBoundary();
877
- const defaultedOptions = client.defaultQueryOptions(options);
878
- defaultedOptions._optimisticResults = isRestoring ? "isRestoring" : "optimistic";
879
- ensureStaleTime(defaultedOptions);
880
- ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary);
881
- useClearResetErrorBoundary(errorResetBoundary);
882
- const [observer] = React__namespace.useState(
883
- () => new Observer(
884
- client,
885
- defaultedOptions
886
- )
887
- );
888
- const result = observer.getOptimisticResult(defaultedOptions);
889
- React__namespace.useSyncExternalStore(
890
- React__namespace.useCallback(
891
- (onStoreChange) => {
892
- const unsubscribe = isRestoring ? () => void 0 : observer.subscribe(utils.notifyManager.batchCalls(onStoreChange));
893
- observer.updateResult();
894
- return unsubscribe;
895
- },
896
- [observer, isRestoring]
897
- ),
898
- () => observer.getCurrentResult(),
899
- () => observer.getCurrentResult()
900
- );
901
- React__namespace.useEffect(() => {
902
- observer.setOptions(defaultedOptions, { listeners: false });
903
- }, [defaultedOptions, observer]);
904
- if (shouldSuspend(defaultedOptions, result)) {
905
- throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary);
906
- }
907
- if (getHasError({
908
- result,
909
- errorResetBoundary,
910
- throwOnError: defaultedOptions.throwOnError,
911
- query: client.getQueryCache().get(defaultedOptions.queryHash)
912
- })) {
913
- throw result.error;
914
- }
915
- return !defaultedOptions.notifyOnChangeProps ? observer.trackResult(result) : result;
916
- }
917
-
918
- function useQuery(options, queryClient) {
919
- return useBaseQuery(options, QueryObserver, queryClient);
920
- }
921
-
922
- const QUERY_KEYS = {
923
- STRIPE_ACCOUNT_DETAILS: "stripe-account-details",
924
- STRIPE_PLATFORM_ACCOUNT_DETAILS: "stripe-platform-account-details",
925
- TRANSACTIONS_LIST: "transactions-list",
926
- PLATFORM_TRANSACTIONS_LIST: "platform-transactions-list",
927
- PAYMENTS_FILTER_OPTIONS: "payments-filter-options",
928
- REFUNDS_LIST: "refunds-list",
929
- SPLITS_LIST: "platform-splits-list",
930
- CONNECTED_ACCOUNT: "connected-account",
931
- STRIPE_ACCOUNTS_LIST: "stripe-accounts-list",
932
- STRIPE_PLATFORM_TRANSACTION: "stripe-platform-transaction",
933
- STRIPE_REFUNDS_LIST: "stripe-refunds-list",
934
- STRIPE_PAYOUTS_LIST: "stripe-payouts-list",
935
- STRIPE_PAYOUT: "stripe-payout",
936
- RAZORPAY_PAYMENTS_LIST: "razorpay-payment-list",
937
- RAZORPAY_ACCOUNT_DETAILS: "razorpay-account-details",
938
- V2_PAYMENTS: "v2-payments"
939
- };
940
-
941
- exports.QUERY_KEYS = QUERY_KEYS;
942
- exports.Query = Query;
943
- exports.useQuery = useQuery;
944
- //# sourceMappingURL=queryConstants-de21eed5.js.map