merchi_sdk_ts 1.0.72-test-b → 1.0.72-test-d
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.
- package/dist/merchi.js +1 -7
- package/dist/request.js +30 -5
- package/package.json +1 -1
- package/src/merchi.ts +1 -8
- package/src/request.ts +36 -2
package/dist/merchi.js
CHANGED
|
@@ -194,16 +194,10 @@ var Merchi = /** @class */ (function () {
|
|
|
194
194
|
if (!determinedBaseUri) {
|
|
195
195
|
determinedBaseUri = 'https://api.merchi.co/';
|
|
196
196
|
}
|
|
197
|
-
// Ensure determinedBaseUri ends with a slash
|
|
197
|
+
// Ensure determinedBaseUri ends with a slash
|
|
198
198
|
if (!determinedBaseUri.endsWith('/')) {
|
|
199
199
|
determinedBaseUri += '/';
|
|
200
200
|
}
|
|
201
|
-
// Check if the URI already includes the API version
|
|
202
|
-
var versionPattern = new RegExp("/".concat(API_VERSION, "/?$"));
|
|
203
|
-
if (!versionPattern.test(determinedBaseUri)) {
|
|
204
|
-
determinedBaseUri += API_VERSION + '/';
|
|
205
|
-
}
|
|
206
|
-
console.log('what is determinedBaseUri', determinedBaseUri);
|
|
207
201
|
this.backendUri = determinedBaseUri;
|
|
208
202
|
// re-export configured versions of all classes
|
|
209
203
|
this.AutomaticPaymentRelationship = this.setupClass(AutomaticPaymentRelationship);
|
package/dist/request.js
CHANGED
|
@@ -45,21 +45,46 @@ var ApiError = /** @class */ (function (_super) {
|
|
|
45
45
|
}(Error));
|
|
46
46
|
export { ApiError };
|
|
47
47
|
export var version = 'v6';
|
|
48
|
+
function ensureVersionInUri(baseUrl) {
|
|
49
|
+
// Ensure baseUrl ends with a slash
|
|
50
|
+
var uri = baseUrl;
|
|
51
|
+
if (!uri.endsWith('/')) {
|
|
52
|
+
uri += '/';
|
|
53
|
+
}
|
|
54
|
+
// Check if the URI already includes a version
|
|
55
|
+
var versionPattern = new RegExp('/v\\d+/?$');
|
|
56
|
+
var match = uri.match(versionPattern);
|
|
57
|
+
if (match) {
|
|
58
|
+
// Extract the version and remove it from the URI
|
|
59
|
+
var foundVersion = match[0].replace(/\//g, '');
|
|
60
|
+
var strippedUri = uri.replace(versionPattern, '/');
|
|
61
|
+
return {
|
|
62
|
+
baseUrl: strippedUri,
|
|
63
|
+
version: foundVersion
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
baseUrl: uri,
|
|
68
|
+
version: version
|
|
69
|
+
};
|
|
70
|
+
}
|
|
48
71
|
export function backendFetch(baseUrl, resource, options) {
|
|
49
72
|
var e_1, _a;
|
|
50
|
-
var
|
|
51
|
-
|
|
73
|
+
var _b = ensureVersionInUri(baseUrl), cleanBaseUrl = _b.baseUrl, apiVersion = _b.version;
|
|
74
|
+
// Remove leading slash from resource if it exists to prevent double slashes
|
|
75
|
+
var cleanResource = resource.startsWith('/') ? resource.slice(1) : resource;
|
|
76
|
+
var url = new URL(cleanBaseUrl + apiVersion + '/' + cleanResource);
|
|
52
77
|
if (options && options.query) {
|
|
53
78
|
try {
|
|
54
|
-
for (var
|
|
55
|
-
var entry =
|
|
79
|
+
for (var _c = __values(options.query), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
80
|
+
var entry = _d.value;
|
|
56
81
|
url.searchParams.append(entry[0], entry[1]);
|
|
57
82
|
}
|
|
58
83
|
}
|
|
59
84
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
60
85
|
finally {
|
|
61
86
|
try {
|
|
62
|
-
if (
|
|
87
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
63
88
|
}
|
|
64
89
|
finally { if (e_1) throw e_1.error; }
|
|
65
90
|
}
|
package/package.json
CHANGED
package/src/merchi.ts
CHANGED
|
@@ -240,18 +240,11 @@ export class Merchi {
|
|
|
240
240
|
determinedBaseUri = 'https://api.merchi.co/';
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
-
// Ensure determinedBaseUri ends with a slash
|
|
243
|
+
// Ensure determinedBaseUri ends with a slash
|
|
244
244
|
if (!determinedBaseUri.endsWith('/')) {
|
|
245
245
|
determinedBaseUri += '/';
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
-
// Check if the URI already includes the API version
|
|
249
|
-
const versionPattern = new RegExp(`/${API_VERSION}/?$`);
|
|
250
|
-
if (!versionPattern.test(determinedBaseUri)) {
|
|
251
|
-
determinedBaseUri += API_VERSION + '/';
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
console.log('what is determinedBaseUri', determinedBaseUri);
|
|
255
248
|
this.backendUri = determinedBaseUri;
|
|
256
249
|
|
|
257
250
|
// re-export configured versions of all classes
|
package/src/request.ts
CHANGED
|
@@ -25,9 +25,43 @@ export class ApiError extends Error {
|
|
|
25
25
|
|
|
26
26
|
export const version = 'v6';
|
|
27
27
|
|
|
28
|
+
interface UriComponents {
|
|
29
|
+
baseUrl: string;
|
|
30
|
+
version: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function ensureVersionInUri(baseUrl: string): UriComponents {
|
|
34
|
+
// Ensure baseUrl ends with a slash
|
|
35
|
+
let uri = baseUrl;
|
|
36
|
+
if (!uri.endsWith('/')) {
|
|
37
|
+
uri += '/';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Check if the URI already includes a version
|
|
41
|
+
const versionPattern = new RegExp('/v\\d+/?$');
|
|
42
|
+
const match = uri.match(versionPattern);
|
|
43
|
+
|
|
44
|
+
if (match) {
|
|
45
|
+
// Extract the version and remove it from the URI
|
|
46
|
+
const foundVersion = match[0].replace(/\//g, '');
|
|
47
|
+
const strippedUri = uri.replace(versionPattern, '/');
|
|
48
|
+
return {
|
|
49
|
+
baseUrl: strippedUri,
|
|
50
|
+
version: foundVersion
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
baseUrl: uri,
|
|
56
|
+
version: version
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
28
60
|
export function backendFetch(baseUrl: string, resource: string, options?: RequestOptions) {
|
|
29
|
-
const
|
|
30
|
-
|
|
61
|
+
const { baseUrl: cleanBaseUrl, version: apiVersion } = ensureVersionInUri(baseUrl);
|
|
62
|
+
// Remove leading slash from resource if it exists to prevent double slashes
|
|
63
|
+
const cleanResource = resource.startsWith('/') ? resource.slice(1) : resource;
|
|
64
|
+
const url = new URL(cleanBaseUrl + apiVersion + '/' + cleanResource);
|
|
31
65
|
if (options && options.query) {
|
|
32
66
|
for (const entry of options.query) {
|
|
33
67
|
url.searchParams.append(entry[0], entry[1]);
|