merchi_sdk_ts 1.0.72-test-c → 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/request.js CHANGED
@@ -51,30 +51,40 @@ function ensureVersionInUri(baseUrl) {
51
51
  if (!uri.endsWith('/')) {
52
52
  uri += '/';
53
53
  }
54
- // Check if the URI already includes the API version
55
- var versionPattern = new RegExp("/".concat(version, "/?$"));
56
- if (!versionPattern.test(uri)) {
57
- uri += version + '/';
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
+ };
58
65
  }
59
- return uri;
66
+ return {
67
+ baseUrl: uri,
68
+ version: version
69
+ };
60
70
  }
61
71
  export function backendFetch(baseUrl, resource, options) {
62
72
  var e_1, _a;
63
- var uriWithVersion = ensureVersionInUri(baseUrl);
73
+ var _b = ensureVersionInUri(baseUrl), cleanBaseUrl = _b.baseUrl, apiVersion = _b.version;
64
74
  // Remove leading slash from resource if it exists to prevent double slashes
65
75
  var cleanResource = resource.startsWith('/') ? resource.slice(1) : resource;
66
- var url = new URL(uriWithVersion + cleanResource);
76
+ var url = new URL(cleanBaseUrl + apiVersion + '/' + cleanResource);
67
77
  if (options && options.query) {
68
78
  try {
69
- for (var _b = __values(options.query), _c = _b.next(); !_c.done; _c = _b.next()) {
70
- var entry = _c.value;
79
+ for (var _c = __values(options.query), _d = _c.next(); !_d.done; _d = _c.next()) {
80
+ var entry = _d.value;
71
81
  url.searchParams.append(entry[0], entry[1]);
72
82
  }
73
83
  }
74
84
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
75
85
  finally {
76
86
  try {
77
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
87
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
78
88
  }
79
89
  finally { if (e_1) throw e_1.error; }
80
90
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "merchi_sdk_ts",
3
- "version": "1.0.72-test-c",
3
+ "version": "1.0.72-test-d",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "repository": "git@github.com:merchisdk/merchi_sdk_ts.git",
package/src/request.ts CHANGED
@@ -25,27 +25,43 @@ export class ApiError extends Error {
25
25
 
26
26
  export const version = 'v6';
27
27
 
28
- function ensureVersionInUri(baseUrl: string): string {
28
+ interface UriComponents {
29
+ baseUrl: string;
30
+ version: string;
31
+ }
32
+
33
+ function ensureVersionInUri(baseUrl: string): UriComponents {
29
34
  // Ensure baseUrl ends with a slash
30
35
  let uri = baseUrl;
31
36
  if (!uri.endsWith('/')) {
32
37
  uri += '/';
33
38
  }
34
39
 
35
- // Check if the URI already includes the API version
36
- const versionPattern = new RegExp(`/${version}/?$`);
37
- if (!versionPattern.test(uri)) {
38
- uri += version + '/';
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
+ };
39
52
  }
40
53
 
41
- return uri;
54
+ return {
55
+ baseUrl: uri,
56
+ version: version
57
+ };
42
58
  }
43
59
 
44
60
  export function backendFetch(baseUrl: string, resource: string, options?: RequestOptions) {
45
- const uriWithVersion = ensureVersionInUri(baseUrl);
61
+ const { baseUrl: cleanBaseUrl, version: apiVersion } = ensureVersionInUri(baseUrl);
46
62
  // Remove leading slash from resource if it exists to prevent double slashes
47
63
  const cleanResource = resource.startsWith('/') ? resource.slice(1) : resource;
48
- const url = new URL(uriWithVersion + cleanResource);
64
+ const url = new URL(cleanBaseUrl + apiVersion + '/' + cleanResource);
49
65
  if (options && options.query) {
50
66
  for (const entry of options.query) {
51
67
  url.searchParams.append(entry[0], entry[1]);