1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
|
/*
This file is part of GNU Taler
(C) 2019-2020 Taler Systems S.A.
GNU Taler is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
import { canonicalizeBaseUrl } from "./helpers.js";
import { AmountString } from "./taler-types.js";
import { URLSearchParams, URL } from "./url.js";
export type TalerUri =
| PayUriResult
| PayTemplateUriResult
| DevExperimentUri
| PayPullUriResult
| PayPushUriResult
| BackupRestoreUri
| RefundUriResult
| RewardUriResult
| WithdrawUriResult
| ExchangeUri
| WithdrawExchangeUri
| AuditorUri;
export interface PayUriResult {
type: TalerUriAction.Pay;
merchantBaseUrl: string;
orderId: string;
sessionId: string;
claimToken?: string;
noncePriv?: string;
}
export interface PayTemplateUriResult {
type: TalerUriAction.PayTemplate;
merchantBaseUrl: string;
templateId: string;
templateParams: Record<string, string>;
}
export interface WithdrawUriResult {
type: TalerUriAction.Withdraw;
bankIntegrationApiBaseUrl: string;
withdrawalOperationId: string;
}
export interface RefundUriResult {
type: TalerUriAction.Refund;
merchantBaseUrl: string;
orderId: string;
}
export interface RewardUriResult {
type: TalerUriAction.Reward;
merchantBaseUrl: string;
merchantRewardId: string;
}
export interface ExchangeUri {
type: TalerUriAction.Exchange;
exchangeBaseUrl: string;
exchangePub: string;
}
export interface AuditorUri {
type: TalerUriAction.Auditor;
auditorBaseUrl: string;
auditorPub: string;
}
export interface PayPushUriResult {
type: TalerUriAction.PayPush;
exchangeBaseUrl: string;
contractPriv: string;
}
export interface PayPullUriResult {
type: TalerUriAction.PayPull;
exchangeBaseUrl: string;
contractPriv: string;
}
export interface DevExperimentUri {
type: TalerUriAction.DevExperiment;
devExperimentId: string;
}
export interface BackupRestoreUri {
type: TalerUriAction.Restore;
walletRootPriv: string;
providers: Array<string>;
}
export interface WithdrawExchangeUri {
type: TalerUriAction.WithdrawExchange;
exchangeBaseUrl: string;
exchangePub: string;
amount?: AmountString;
}
/**
* Parse a taler[+http]://withdraw URI.
* Return undefined if not passed a valid URI.
*/
export function parseWithdrawUri(s: string): WithdrawUriResult | undefined {
const pi = parseProtoInfo(s, "withdraw");
if (!pi) {
return undefined;
}
const parts = pi.rest.split("/");
if (parts.length < 2) {
return undefined;
}
const host = parts[0].toLowerCase();
const pathSegments = parts.slice(1, parts.length - 1);
/**
* The statement below does not tolerate a slash-ended URI.
* This results in (1) the withdrawalId being passed as the
* empty string, and (2) the bankIntegrationApi ending with the
* actual withdrawal operation ID. That can be fixed by
* trimming the parts-list. FIXME
*/
const withdrawId = parts[parts.length - 1];
const p = [host, ...pathSegments].join("/");
return {
type: TalerUriAction.Withdraw,
bankIntegrationApiBaseUrl: canonicalizeBaseUrl(`${pi.innerProto}://${p}/`),
withdrawalOperationId: withdrawId,
};
}
/**
* @deprecated use TalerUriAction
*/
export enum TalerUriType {
TalerPay = "taler-pay",
TalerTemplate = "taler-template",
TalerPayTemplate = "taler-pay-template",
TalerWithdraw = "taler-withdraw",
TalerTip = "taler-tip",
TalerRefund = "taler-refund",
TalerPayPush = "taler-pay-push",
TalerPayPull = "taler-pay-pull",
TalerRecovery = "taler-recovery",
TalerDevExperiment = "taler-dev-experiment",
Unknown = "unknown",
}
const talerActionPayPull = "pay-pull";
const talerActionPayPush = "pay-push";
const talerActionPayTemplate = "pay-template";
export enum TalerUriAction {
Pay = "pay",
Withdraw = "withdraw",
Refund = "refund",
Reward = "reward",
PayPull = "pay-pull",
PayPush = "pay-push",
PayTemplate = "pay-template",
Exchange = "exchange",
Auditor = "auditor",
Restore = "restore",
DevExperiment = "dev-experiment",
WithdrawExchange = "withdraw-exchange",
}
interface TalerUriProtoInfo {
innerProto: "http" | "https";
rest: string;
}
function parseProtoInfo(
s: string,
action: string,
): TalerUriProtoInfo | undefined {
const pfxPlain = `taler://${action}/`;
const pfxHttp = `taler+http://${action}/`;
if (s.toLowerCase().startsWith(pfxPlain)) {
return {
innerProto: "https",
rest: s.substring(pfxPlain.length),
};
} else if (s.toLowerCase().startsWith(pfxHttp)) {
return {
innerProto: "http",
rest: s.substring(pfxHttp.length),
};
} else {
return undefined;
}
}
type Parser = (s: string) => TalerUri | undefined;
const parsers: { [A in TalerUriAction]: Parser } = {
[TalerUriAction.Pay]: parsePayUri,
[TalerUriAction.PayPull]: parsePayPullUri,
[TalerUriAction.PayPush]: parsePayPushUri,
[TalerUriAction.PayTemplate]: parsePayTemplateUri,
[TalerUriAction.Restore]: parseRestoreUri,
[TalerUriAction.Refund]: parseRefundUri,
[TalerUriAction.Reward]: parseRewardUri,
[TalerUriAction.Withdraw]: parseWithdrawUri,
[TalerUriAction.DevExperiment]: parseDevExperimentUri,
[TalerUriAction.Exchange]: parseExchangeUri,
[TalerUriAction.Auditor]: parseAuditorUri,
[TalerUriAction.WithdrawExchange]: parseWithdrawExchangeUri,
};
export function parseTalerUri(string: string): TalerUri | undefined {
const https = string.startsWith("taler://");
const http = string.startsWith("taler+http://");
if (!https && !http) return undefined;
const actionStart = https ? 8 : 13;
const actionEnd = string.indexOf("/", actionStart + 1);
const action = string.substring(actionStart, actionEnd);
const found = Object.values(TalerUriAction).find((x) => x === action);
if (!found) return undefined;
return parsers[found](string);
}
export function stringifyTalerUri(uri: TalerUri): string {
switch (uri.type) {
case TalerUriAction.DevExperiment: {
return stringifyDevExperimentUri(uri);
}
case TalerUriAction.Pay: {
return stringifyPayUri(uri);
}
case TalerUriAction.PayPull: {
return stringifyPayPullUri(uri);
}
case TalerUriAction.PayPush: {
return stringifyPayPushUri(uri);
}
case TalerUriAction.PayTemplate: {
return stringifyPayTemplateUri(uri);
}
case TalerUriAction.Restore: {
return stringifyRestoreUri(uri);
}
case TalerUriAction.Refund: {
return stringifyRefundUri(uri);
}
case TalerUriAction.Reward: {
return stringifyRewardUri(uri);
}
case TalerUriAction.Withdraw: {
return stringifyWithdrawUri(uri);
}
case TalerUriAction.Exchange: {
return stringifyExchangeUri(uri);
}
case TalerUriAction.WithdrawExchange: {
return stringifyWithdrawExchange(uri);
}
case TalerUriAction.Auditor: {
return stringifyAuditorUri(uri);
}
}
}
/**
* Parse a taler[+http]://pay URI.
* Return undefined if not passed a valid URI.
*/
export function parsePayUri(s: string): PayUriResult | undefined {
const pi = parseProtoInfo(s, "pay");
if (!pi) {
return undefined;
}
const c = pi?.rest.split("?");
const q = new URLSearchParams(c[1] ?? "");
const claimToken = q.get("c") ?? undefined;
const noncePriv = q.get("n") ?? undefined;
const parts = c[0].split("/");
if (parts.length < 3) {
return undefined;
}
const host = parts[0].toLowerCase();
const sessionId = parts[parts.length - 1];
const orderId = parts[parts.length - 2];
const pathSegments = parts.slice(1, parts.length - 2);
const p = [host, ...pathSegments].join("/");
const merchantBaseUrl = canonicalizeBaseUrl(`${pi.innerProto}://${p}/`);
return {
type: TalerUriAction.Pay,
merchantBaseUrl,
orderId,
sessionId,
claimToken,
noncePriv,
};
}
export function parsePayTemplateUri(
uriString: string,
): PayTemplateUriResult | undefined {
const pi = parseProtoInfo(uriString, talerActionPayTemplate);
if (!pi) {
return undefined;
}
const c = pi.rest.split("?");
const parts = c[0].split("/");
if (parts.length < 2) {
return undefined;
}
const q = new URLSearchParams(c[1] ?? "");
const params: Record<string, string> = {};
q.forEach((v, k) => {
params[k] = v;
});
const host = parts[0].toLowerCase();
const templateId = parts[parts.length - 1];
const pathSegments = parts.slice(1, parts.length - 1);
const hostAndSegments = [host, ...pathSegments].join("/");
const merchantBaseUrl = canonicalizeBaseUrl(
`${pi.innerProto}://${hostAndSegments}/`,
);
return {
type: TalerUriAction.PayTemplate,
merchantBaseUrl,
templateId,
templateParams: params,
};
}
export function parsePayPushUri(s: string): PayPushUriResult | undefined {
const pi = parseProtoInfo(s, talerActionPayPush);
if (!pi) {
return undefined;
}
const c = pi?.rest.split("?");
const parts = c[0].split("/");
if (parts.length < 2) {
return undefined;
}
const host = parts[0].toLowerCase();
const contractPriv = parts[parts.length - 1];
const pathSegments = parts.slice(1, parts.length - 1);
const hostAndSegments = [host, ...pathSegments].join("/");
const exchangeBaseUrl = canonicalizeBaseUrl(
`${pi.innerProto}://${hostAndSegments}/`,
);
return {
type: TalerUriAction.PayPush,
exchangeBaseUrl,
contractPriv,
};
}
export function parsePayPullUri(s: string): PayPullUriResult | undefined {
const pi = parseProtoInfo(s, talerActionPayPull);
if (!pi) {
return undefined;
}
const c = pi?.rest.split("?");
const parts = c[0].split("/");
if (parts.length < 2) {
return undefined;
}
const host = parts[0].toLowerCase();
const contractPriv = parts[parts.length - 1];
const pathSegments = parts.slice(1, parts.length - 1);
const hostAndSegments = [host, ...pathSegments].join("/");
const exchangeBaseUrl = canonicalizeBaseUrl(
`${pi.innerProto}://${hostAndSegments}/`,
);
return {
type: TalerUriAction.PayPull,
exchangeBaseUrl,
contractPriv,
};
}
/**
* Parse a taler[+http]://reward URI.
* Return undefined if not passed a valid URI.
*/
export function parseRewardUri(s: string): RewardUriResult | undefined {
const pi = parseProtoInfo(s, "reward");
if (!pi) {
return undefined;
}
const c = pi?.rest.split("?");
const parts = c[0].split("/");
if (parts.length < 2) {
return undefined;
}
const host = parts[0].toLowerCase();
const rewardId = parts[parts.length - 1];
const pathSegments = parts.slice(1, parts.length - 1);
const hostAndSegments = [host, ...pathSegments].join("/");
const merchantBaseUrl = canonicalizeBaseUrl(
`${pi.innerProto}://${hostAndSegments}/`,
);
return {
type: TalerUriAction.Reward,
merchantBaseUrl,
merchantRewardId: rewardId,
};
}
export function parseExchangeUri(s: string): ExchangeUri | undefined {
const pi = parseProtoInfo(s, "exchange");
if (!pi) {
return undefined;
}
const c = pi?.rest.split("?");
const parts = c[0].split("/");
if (parts.length < 2) {
return undefined;
}
const host = parts[0].toLowerCase();
const exchangePub = parts[parts.length - 1];
const pathSegments = parts.slice(1, parts.length - 1);
const hostAndSegments = [host, ...pathSegments].join("/");
const exchangeBaseUrl = canonicalizeBaseUrl(
`${pi.innerProto}://${hostAndSegments}/`,
);
return {
type: TalerUriAction.Exchange,
exchangeBaseUrl,
exchangePub,
};
}
export function parseWithdrawExchangeUri(
s: string,
): WithdrawExchangeUri | undefined {
const pi = parseProtoInfo(s, "withdraw-exchange");
if (!pi) {
return undefined;
}
const c = pi?.rest.split("?");
const parts = c[0].split("/");
if (parts.length < 2) {
return undefined;
}
const host = parts[0].toLowerCase();
const exchangePub = parts[parts.length - 1];
const pathSegments = parts.slice(1, parts.length - 1);
const hostAndSegments = [host, ...pathSegments].join("/");
const exchangeBaseUrl = canonicalizeBaseUrl(
`${pi.innerProto}://${hostAndSegments}/`,
);
const q = new URLSearchParams(c[1] ?? "");
const amount = q.get("a") ?? undefined;
return {
type: TalerUriAction.WithdrawExchange,
exchangeBaseUrl,
exchangePub,
amount,
};
}
export function parseAuditorUri(s: string): AuditorUri | undefined {
const pi = parseProtoInfo(s, "auditor");
if (!pi) {
return undefined;
}
const c = pi?.rest.split("?");
const parts = c[0].split("/");
if (parts.length < 2) {
return undefined;
}
const host = parts[0].toLowerCase();
const auditorPub = parts[parts.length - 1];
const pathSegments = parts.slice(1, parts.length - 1);
const hostAndSegments = [host, ...pathSegments].join("/");
const auditorBaseUrl = canonicalizeBaseUrl(
`${pi.innerProto}://${hostAndSegments}/`,
);
return {
type: TalerUriAction.Auditor,
auditorBaseUrl,
auditorPub,
};
}
/**
* Parse a taler[+http]://refund URI.
* Return undefined if not passed a valid URI.
*/
export function parseRefundUri(s: string): RefundUriResult | undefined {
const pi = parseProtoInfo(s, "refund");
if (!pi) {
return undefined;
}
const c = pi?.rest.split("?");
const parts = c[0].split("/");
if (parts.length < 3) {
return undefined;
}
const host = parts[0].toLowerCase();
const sessionId = parts[parts.length - 1];
const orderId = parts[parts.length - 2];
const pathSegments = parts.slice(1, parts.length - 2);
const hostAndSegments = [host, ...pathSegments].join("/");
const merchantBaseUrl = canonicalizeBaseUrl(
`${pi.innerProto}://${hostAndSegments}/`,
);
return {
type: TalerUriAction.Refund,
merchantBaseUrl,
orderId,
};
}
export function parseDevExperimentUri(s: string): DevExperimentUri | undefined {
const pi = parseProtoInfo(s, "dev-experiment");
const c = pi?.rest.split("?");
if (!c) {
return undefined;
}
const parts = c[0].split("/");
return {
type: TalerUriAction.DevExperiment,
devExperimentId: parts[0],
};
}
export function parseRestoreUri(uri: string): BackupRestoreUri | undefined {
const pi = parseProtoInfo(uri, "restore");
if (!pi) {
return undefined;
}
const c = pi.rest.split("?");
const parts = c[0].split("/");
if (parts.length < 2) {
return undefined;
}
const walletRootPriv = parts[0];
if (!walletRootPriv) return undefined;
const providers = new Array<string>();
parts[1].split(",").map((name) => {
const url = canonicalizeBaseUrl(
`${pi.innerProto}://${decodeURIComponent(name)}/`,
);
providers.push(url);
});
return {
type: TalerUriAction.Restore,
walletRootPriv,
providers,
};
}
// ================================================
// To string functions
// ================================================
/**
* @deprecated use stringifyRecoveryUri
*/
export function constructRecoveryUri(args: {
walletRootPriv: string;
providers: string[];
}): string {
return stringifyRestoreUri(args);
}
/**
* @deprecated stringifyPayPullUri
*/
export function constructPayPullUri(args: {
exchangeBaseUrl: string;
contractPriv: string;
}): string {
return stringifyPayPullUri(args);
}
/**
* @deprecated use stringifyPayPushUri
*/
export function constructPayPushUri(args: {
exchangeBaseUrl: string;
contractPriv: string;
}): string {
return stringifyPayPushUri(args);
}
/**
*
* @deprecated use stringifyPayUri
*/
export function constructPayUri(
merchantBaseUrl: string,
orderId: string,
sessionId: string,
claimToken?: string,
noncePriv?: string,
): string {
return stringifyPayUri({
merchantBaseUrl,
orderId,
sessionId,
claimToken,
noncePriv,
});
}
export function stringifyPayUri({
merchantBaseUrl,
orderId,
sessionId,
claimToken,
noncePriv,
}: Omit<PayUriResult, "type">): string {
const { proto, path, query } = getUrlInfo(merchantBaseUrl, {
c: claimToken,
n: noncePriv,
});
return `${proto}://pay/${path}${orderId}/${sessionId}${query}`;
}
export function stringifyPayPullUri({
contractPriv,
exchangeBaseUrl,
}: Omit<PayPullUriResult, "type">): string {
const { proto, path } = getUrlInfo(exchangeBaseUrl);
return `${proto}://pay-pull/${path}${contractPriv}`;
}
export function stringifyPayPushUri({
contractPriv,
exchangeBaseUrl,
}: Omit<PayPushUriResult, "type">): string {
const { proto, path } = getUrlInfo(exchangeBaseUrl);
return `${proto}://pay-push/${path}${contractPriv}`;
}
export function stringifyRestoreUri({
providers,
walletRootPriv,
}: Omit<BackupRestoreUri, "type">): string {
const list = providers
.map((url) => `${encodeURIComponent(new URL(url).href)}`)
.join(",");
return `taler://restore/${walletRootPriv}/${list}`;
}
export function stringifyWithdrawExchange({
exchangeBaseUrl,
exchangePub,
amount,
}: Omit<WithdrawExchangeUri, "type">): string {
const { proto, path, query } = getUrlInfo(exchangeBaseUrl, {
a: amount,
});
return `${proto}://withdraw-exchange/${path}${exchangePub}${query}`;
}
export function stringifyDevExperimentUri({
devExperimentId,
}: Omit<DevExperimentUri, "type">): string {
return `taler://dev-experiment/${devExperimentId}`;
}
export function stringifyPayTemplateUri({
merchantBaseUrl,
templateId,
templateParams,
}: Omit<PayTemplateUriResult, "type">): string {
const { proto, path, query } = getUrlInfo(merchantBaseUrl, templateParams);
return `${proto}://pay-template/${path}${templateId}${query}`;
}
export function stringifyRefundUri({
merchantBaseUrl,
orderId,
}: Omit<RefundUriResult, "type">): string {
const { proto, path } = getUrlInfo(merchantBaseUrl);
return `${proto}://refund/${path}${orderId}`;
}
export function stringifyRewardUri({
merchantBaseUrl,
merchantRewardId,
}: Omit<RewardUriResult, "type">): string {
const { proto, path } = getUrlInfo(merchantBaseUrl);
return `${proto}://reward/${path}${merchantRewardId}`;
}
export function stringifyExchangeUri({
exchangeBaseUrl,
exchangePub,
}: Omit<ExchangeUri, "type">): string {
const { proto, path } = getUrlInfo(exchangeBaseUrl);
return `${proto}://exchange/${path}${exchangePub}`;
}
export function stringifyAuditorUri({
auditorBaseUrl,
auditorPub,
}: Omit<AuditorUri, "type">): string {
const { proto, path } = getUrlInfo(auditorBaseUrl);
return `${proto}://auditor/${path}${auditorPub}`;
}
export function stringifyWithdrawUri({
bankIntegrationApiBaseUrl,
withdrawalOperationId,
}: Omit<WithdrawUriResult, "type">): string {
const { proto, path } = getUrlInfo(bankIntegrationApiBaseUrl);
return `${proto}://withdraw/${path}${withdrawalOperationId}`;
}
/**
* Use baseUrl to defined http or https
* create path using host+port+pathname
* use params to create a query parameter string or empty
*
* @param baseUrl
* @param params
* @returns
*/
function getUrlInfo(
baseUrl: string,
params: Record<string, string | undefined> = {},
): { proto: string; path: string; query: string } {
const url = new URL(baseUrl);
let proto: string;
if (url.protocol === "https:") {
proto = "taler";
} else if (url.protocol === "http:") {
proto = "taler+http";
} else {
throw Error(`Unsupported URL protocol in ${baseUrl}`);
}
let path = url.hostname;
if (url.port) {
path = path + ":" + url.port;
}
if (url.pathname) {
path = path + url.pathname;
}
if (!path.endsWith("/")) {
path = path + "/";
}
const qp = new URLSearchParams();
let withParams = false;
Object.entries(params).forEach(([name, value]) => {
if (value !== undefined) {
withParams = true;
qp.append(name, value);
}
});
const query = withParams ? "?" + qp.toString() : "";
return { proto, path, query };
}
|