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