@moonbase.sh/storefront-api 3.5.0 → 3.5.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.
package/dist/index.cjs CHANGED
@@ -808,7 +808,8 @@ var IdentityEndpoints = class {
808
808
  headers: {
809
809
  "Accept": "application/json",
810
810
  "Content-Type": "text/plain",
811
- "x-mb-cors": "1"
811
+ "x-mb-cors": "1",
812
+ "x-mb-client": this.api.clientHeader
812
813
  },
813
814
  body: password
814
815
  });
@@ -833,7 +834,8 @@ var IdentityEndpoints = class {
833
834
  headers: {
834
835
  "Accept": "application/json",
835
836
  "Content-Type": "application/json",
836
- "x-mb-cors": "1"
837
+ "x-mb-cors": "1",
838
+ "x-mb-client": this.api.clientHeader
837
839
  },
838
840
  body: JSON.stringify({
839
841
  name,
@@ -899,7 +901,8 @@ var IdentityEndpoints = class {
899
901
  headers: {
900
902
  "Accept": "application/json",
901
903
  "Content-Type": "text/plain",
902
- "x-mb-cors": "1"
904
+ "x-mb-cors": "1",
905
+ "x-mb-client": this.api.clientHeader
903
906
  },
904
907
  body: newPassword
905
908
  });
@@ -1065,8 +1068,8 @@ var ProductEndpoints = class {
1065
1068
  this.api = api;
1066
1069
  this.configuration = configuration;
1067
1070
  }
1068
- async get(productId, version) {
1069
- const response = await this.api.fetch(`/api/customer/inventory/products/${productId}${version ? `?version=${version}${this.configuration.includeManifests ? "&includeManifests=true" : ""}` : this.configuration.includeManifests ? "?includeManifests=true" : ""}`, productSummarySchema);
1071
+ async get(productId, version2) {
1072
+ const response = await this.api.fetch(`/api/customer/inventory/products/${productId}${version2 ? `?version=${version2}${this.configuration.includeManifests ? "&includeManifests=true" : ""}` : this.configuration.includeManifests ? "?includeManifests=true" : ""}`, productSummarySchema);
1070
1073
  return response.data;
1071
1074
  }
1072
1075
  async getOwned(nextUrl) {
@@ -1094,15 +1097,24 @@ var ProductEndpoints = class {
1094
1097
  // src/inventory/subscriptions/endpoints.ts
1095
1098
  var import_zod14 = require("zod");
1096
1099
 
1100
+ // package.json
1101
+ var version = "3.5.1";
1102
+
1103
+ // src/utils/client.ts
1104
+ function buildClientHeader(sdk) {
1105
+ return `${sdk != null ? sdk : ""} @moonbase.sh/storefront-api/${version}`.trim().replace(/\s+/g, " ");
1106
+ }
1107
+
1097
1108
  // src/utils/api.ts
1098
1109
  function objectToQuery(obj) {
1099
1110
  return Object.entries(obj != null ? obj : {}).filter(([_, value]) => value !== void 0).map(([key, value]) => `${key}=${encodeURIComponent(value instanceof Date ? value.toISOString() : value)}`).join("&");
1100
1111
  }
1101
1112
  var MoonbaseApi = class {
1102
- constructor(baseUrl, tokenStore, logger) {
1113
+ constructor(baseUrl, tokenStore, logger, sdk) {
1103
1114
  this.baseUrl = baseUrl;
1104
1115
  this.tokenStore = tokenStore;
1105
1116
  this.logger = logger;
1117
+ this.clientHeader = buildClientHeader(sdk);
1106
1118
  }
1107
1119
  async authenticatedFetch(path, schema, options) {
1108
1120
  if (!this.tokenStore.user)
@@ -1127,7 +1139,8 @@ var MoonbaseApi = class {
1127
1139
  // While this fetch can be anonymous, we add the token if we have it
1128
1140
  ...accessToken ? { Authorization: `Bearer ${accessToken}` } : {},
1129
1141
  // Force CORS on all calls
1130
- "x-mb-cors": "1"
1142
+ "x-mb-cors": "1",
1143
+ "x-mb-client": this.clientHeader
1131
1144
  },
1132
1145
  body: (options == null ? void 0 : options.body) ? contentType !== "application/json" ? options.body : JSON.stringify(options.body) : void 0,
1133
1146
  signal: options == null ? void 0 : options.abort,
@@ -1186,7 +1199,8 @@ var MoonbaseApi = class {
1186
1199
  method: "POST",
1187
1200
  headers: {
1188
1201
  "Accept": "application/json",
1189
- "Content-Type": "application/json"
1202
+ "Content-Type": "application/json",
1203
+ "x-mb-client": this.clientHeader
1190
1204
  },
1191
1205
  body: JSON.stringify({
1192
1206
  title: "Parse error",
@@ -1208,7 +1222,8 @@ var MoonbaseApi = class {
1208
1222
  method: "POST",
1209
1223
  headers: {
1210
1224
  "Accept": "application/json",
1211
- "Content-Type": "application/json"
1225
+ "Content-Type": "application/json",
1226
+ "x-mb-client": this.clientHeader
1212
1227
  },
1213
1228
  body: JSON.stringify({
1214
1229
  title: "Request error",
@@ -1860,7 +1875,8 @@ var _TokenStore = class _TokenStore {
1860
1875
  headers: {
1861
1876
  "Accept": "application/json",
1862
1877
  "Content-Type": "text/plain",
1863
- "x-mb-cors": "1"
1878
+ "x-mb-cors": "1",
1879
+ "x-mb-client": buildClientHeader(this.configuration.sdk)
1864
1880
  },
1865
1881
  body: this.tokens.accessToken
1866
1882
  });
@@ -2579,7 +2595,7 @@ var MoonbaseClient = class {
2579
2595
  this.configuration.endpoint = this.configuration.endpoint.replace(/\/$/, "");
2580
2596
  this.logger = (_a = this.configuration.logger) != null ? _a : new ConsoleLogger();
2581
2597
  this.tokenStore = new TokenStore(configuration);
2582
- this.api = new MoonbaseApi(this.configuration.endpoint, this.tokenStore, this.logger);
2598
+ this.api = new MoonbaseApi(this.configuration.endpoint, this.tokenStore, this.logger, this.configuration.sdk);
2583
2599
  this.storefront = new StorefrontEndpoints(this.api, this.configuration);
2584
2600
  this.identity = new IdentityEndpoints(this.api, this.tokenStore, this.logger);
2585
2601
  this.communications = new CommunicationsEndpoints(this.api);
package/dist/index.d.cts CHANGED
@@ -132,7 +132,13 @@ declare class MoonbaseApi {
132
132
  baseUrl: string;
133
133
  private tokenStore;
134
134
  private logger;
135
- constructor(baseUrl: string, tokenStore: ITokenStore, logger: ILogger);
135
+ /**
136
+ * The `x-mb-client` header this client sends with every request.
137
+ *
138
+ * @internal
139
+ */
140
+ readonly clientHeader: string;
141
+ constructor(baseUrl: string, tokenStore: ITokenStore, logger: ILogger, sdk?: string);
136
142
  authenticatedFetch<T extends ZodTypeAny>(path: string, schema: T | null, options?: FetchOptions): Promise<Response<z.infer<T>>>;
137
143
  fetch<T extends ZodTypeAny>(path: string, schema: T | null, options?: FetchOptions): Promise<Response<z.infer<T>>>;
138
144
  private reportParsingProblem;
@@ -47174,6 +47180,14 @@ interface MoonbaseConfiguration {
47174
47180
  includeManifests?: boolean;
47175
47181
  store?: IStore;
47176
47182
  logger?: ILogger;
47183
+ /**
47184
+ * Product tokens (`name/version`) of an SDK wrapping this one, such as
47185
+ * `@moonbase.sh/vue/3.6.1`, sent ahead of this package's own token in the
47186
+ * `x-mb-client` header.
47187
+ *
47188
+ * @internal
47189
+ */
47190
+ sdk?: string;
47177
47191
  }
47178
47192
  declare class MoonbaseClient {
47179
47193
  private readonly configuration;
package/dist/index.d.ts CHANGED
@@ -132,7 +132,13 @@ declare class MoonbaseApi {
132
132
  baseUrl: string;
133
133
  private tokenStore;
134
134
  private logger;
135
- constructor(baseUrl: string, tokenStore: ITokenStore, logger: ILogger);
135
+ /**
136
+ * The `x-mb-client` header this client sends with every request.
137
+ *
138
+ * @internal
139
+ */
140
+ readonly clientHeader: string;
141
+ constructor(baseUrl: string, tokenStore: ITokenStore, logger: ILogger, sdk?: string);
136
142
  authenticatedFetch<T extends ZodTypeAny>(path: string, schema: T | null, options?: FetchOptions): Promise<Response<z.infer<T>>>;
137
143
  fetch<T extends ZodTypeAny>(path: string, schema: T | null, options?: FetchOptions): Promise<Response<z.infer<T>>>;
138
144
  private reportParsingProblem;
@@ -47174,6 +47180,14 @@ interface MoonbaseConfiguration {
47174
47180
  includeManifests?: boolean;
47175
47181
  store?: IStore;
47176
47182
  logger?: ILogger;
47183
+ /**
47184
+ * Product tokens (`name/version`) of an SDK wrapping this one, such as
47185
+ * `@moonbase.sh/vue/3.6.1`, sent ahead of this package's own token in the
47186
+ * `x-mb-client` header.
47187
+ *
47188
+ * @internal
47189
+ */
47190
+ sdk?: string;
47177
47191
  }
47178
47192
  declare class MoonbaseClient {
47179
47193
  private readonly configuration;
package/dist/index.js CHANGED
@@ -746,7 +746,8 @@ var IdentityEndpoints = class {
746
746
  headers: {
747
747
  "Accept": "application/json",
748
748
  "Content-Type": "text/plain",
749
- "x-mb-cors": "1"
749
+ "x-mb-cors": "1",
750
+ "x-mb-client": this.api.clientHeader
750
751
  },
751
752
  body: password
752
753
  });
@@ -771,7 +772,8 @@ var IdentityEndpoints = class {
771
772
  headers: {
772
773
  "Accept": "application/json",
773
774
  "Content-Type": "application/json",
774
- "x-mb-cors": "1"
775
+ "x-mb-cors": "1",
776
+ "x-mb-client": this.api.clientHeader
775
777
  },
776
778
  body: JSON.stringify({
777
779
  name,
@@ -837,7 +839,8 @@ var IdentityEndpoints = class {
837
839
  headers: {
838
840
  "Accept": "application/json",
839
841
  "Content-Type": "text/plain",
840
- "x-mb-cors": "1"
842
+ "x-mb-cors": "1",
843
+ "x-mb-client": this.api.clientHeader
841
844
  },
842
845
  body: newPassword
843
846
  });
@@ -1003,8 +1006,8 @@ var ProductEndpoints = class {
1003
1006
  this.api = api;
1004
1007
  this.configuration = configuration;
1005
1008
  }
1006
- async get(productId, version) {
1007
- const response = await this.api.fetch(`/api/customer/inventory/products/${productId}${version ? `?version=${version}${this.configuration.includeManifests ? "&includeManifests=true" : ""}` : this.configuration.includeManifests ? "?includeManifests=true" : ""}`, productSummarySchema);
1009
+ async get(productId, version2) {
1010
+ const response = await this.api.fetch(`/api/customer/inventory/products/${productId}${version2 ? `?version=${version2}${this.configuration.includeManifests ? "&includeManifests=true" : ""}` : this.configuration.includeManifests ? "?includeManifests=true" : ""}`, productSummarySchema);
1008
1011
  return response.data;
1009
1012
  }
1010
1013
  async getOwned(nextUrl) {
@@ -1032,15 +1035,24 @@ var ProductEndpoints = class {
1032
1035
  // src/inventory/subscriptions/endpoints.ts
1033
1036
  import { z as z14 } from "zod";
1034
1037
 
1038
+ // package.json
1039
+ var version = "3.5.1";
1040
+
1041
+ // src/utils/client.ts
1042
+ function buildClientHeader(sdk) {
1043
+ return `${sdk != null ? sdk : ""} @moonbase.sh/storefront-api/${version}`.trim().replace(/\s+/g, " ");
1044
+ }
1045
+
1035
1046
  // src/utils/api.ts
1036
1047
  function objectToQuery(obj) {
1037
1048
  return Object.entries(obj != null ? obj : {}).filter(([_, value]) => value !== void 0).map(([key, value]) => `${key}=${encodeURIComponent(value instanceof Date ? value.toISOString() : value)}`).join("&");
1038
1049
  }
1039
1050
  var MoonbaseApi = class {
1040
- constructor(baseUrl, tokenStore, logger) {
1051
+ constructor(baseUrl, tokenStore, logger, sdk) {
1041
1052
  this.baseUrl = baseUrl;
1042
1053
  this.tokenStore = tokenStore;
1043
1054
  this.logger = logger;
1055
+ this.clientHeader = buildClientHeader(sdk);
1044
1056
  }
1045
1057
  async authenticatedFetch(path, schema, options) {
1046
1058
  if (!this.tokenStore.user)
@@ -1065,7 +1077,8 @@ var MoonbaseApi = class {
1065
1077
  // While this fetch can be anonymous, we add the token if we have it
1066
1078
  ...accessToken ? { Authorization: `Bearer ${accessToken}` } : {},
1067
1079
  // Force CORS on all calls
1068
- "x-mb-cors": "1"
1080
+ "x-mb-cors": "1",
1081
+ "x-mb-client": this.clientHeader
1069
1082
  },
1070
1083
  body: (options == null ? void 0 : options.body) ? contentType !== "application/json" ? options.body : JSON.stringify(options.body) : void 0,
1071
1084
  signal: options == null ? void 0 : options.abort,
@@ -1124,7 +1137,8 @@ var MoonbaseApi = class {
1124
1137
  method: "POST",
1125
1138
  headers: {
1126
1139
  "Accept": "application/json",
1127
- "Content-Type": "application/json"
1140
+ "Content-Type": "application/json",
1141
+ "x-mb-client": this.clientHeader
1128
1142
  },
1129
1143
  body: JSON.stringify({
1130
1144
  title: "Parse error",
@@ -1146,7 +1160,8 @@ var MoonbaseApi = class {
1146
1160
  method: "POST",
1147
1161
  headers: {
1148
1162
  "Accept": "application/json",
1149
- "Content-Type": "application/json"
1163
+ "Content-Type": "application/json",
1164
+ "x-mb-client": this.clientHeader
1150
1165
  },
1151
1166
  body: JSON.stringify({
1152
1167
  title: "Request error",
@@ -1798,7 +1813,8 @@ var _TokenStore = class _TokenStore {
1798
1813
  headers: {
1799
1814
  "Accept": "application/json",
1800
1815
  "Content-Type": "text/plain",
1801
- "x-mb-cors": "1"
1816
+ "x-mb-cors": "1",
1817
+ "x-mb-client": buildClientHeader(this.configuration.sdk)
1802
1818
  },
1803
1819
  body: this.tokens.accessToken
1804
1820
  });
@@ -2517,7 +2533,7 @@ var MoonbaseClient = class {
2517
2533
  this.configuration.endpoint = this.configuration.endpoint.replace(/\/$/, "");
2518
2534
  this.logger = (_a = this.configuration.logger) != null ? _a : new ConsoleLogger();
2519
2535
  this.tokenStore = new TokenStore(configuration);
2520
- this.api = new MoonbaseApi(this.configuration.endpoint, this.tokenStore, this.logger);
2536
+ this.api = new MoonbaseApi(this.configuration.endpoint, this.tokenStore, this.logger, this.configuration.sdk);
2521
2537
  this.storefront = new StorefrontEndpoints(this.api, this.configuration);
2522
2538
  this.identity = new IdentityEndpoints(this.api, this.tokenStore, this.logger);
2523
2539
  this.communications = new CommunicationsEndpoints(this.api);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/storefront-api",
3
3
  "type": "module",
4
- "version": "3.5.0",
4
+ "version": "3.5.1",
5
5
  "description": "Package to let you build storefronts with Moonbase.sh as payment and delivery provider",
6
6
  "author": "Tobias Lønnerød Madsen <m@dsen.tv>",
7
7
  "license": "MIT",