@reactionary/feeds 0.10.51 → 0.10.52
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/cli.cjs +484 -342
- package/package.json +9 -9
package/cli.cjs
CHANGED
|
@@ -128372,7 +128372,7 @@ var init_configuration_schema5 = __esm({
|
|
|
128372
128372
|
});
|
|
128373
128373
|
|
|
128374
128374
|
// packages/medusa/src/schema/medusa.schema.ts
|
|
128375
|
-
var MedusaCartIdentifierSchema, MedusaOrderIdentifierSchema, MedusaRegionSchema, MedusaSessionSchema;
|
|
128375
|
+
var MedusaCartIdentifierSchema, MedusaOrderIdentifierSchema, MedusaRegionSchema, MedusaCachedPluginListSchema, MedusaSessionSchema;
|
|
128376
128376
|
var init_medusa_schema = __esm({
|
|
128377
128377
|
"packages/medusa/src/schema/medusa.schema.ts"() {
|
|
128378
128378
|
"use strict";
|
|
@@ -128389,6 +128389,9 @@ var init_medusa_schema = __esm({
|
|
|
128389
128389
|
name: string2(),
|
|
128390
128390
|
currency_code: string2()
|
|
128391
128391
|
});
|
|
128392
|
+
MedusaCachedPluginListSchema = looseObject({
|
|
128393
|
+
plugins: array(string2())
|
|
128394
|
+
});
|
|
128392
128395
|
MedusaSessionSchema = looseObject({
|
|
128393
128396
|
activeCartId: MedusaCartIdentifierSchema.optional(),
|
|
128394
128397
|
allOwnedCarts: record(string2(), array(MedusaCartIdentifierSchema)).optional(),
|
|
@@ -158017,6 +158020,235 @@ var require_dist3 = __commonJS({
|
|
|
158017
158020
|
}
|
|
158018
158021
|
});
|
|
158019
158022
|
|
|
158023
|
+
// packages/medusa/src/core/client.ts
|
|
158024
|
+
var import_debug21, debug21, SESSION_KEY2, RequestContextTokenStore2, Medusa, MedusaAdminAPI, MedusaAPI;
|
|
158025
|
+
var init_client6 = __esm({
|
|
158026
|
+
"packages/medusa/src/core/client.ts"() {
|
|
158027
|
+
"use strict";
|
|
158028
|
+
init_esm2();
|
|
158029
|
+
import_debug21 = __toESM(require_src(), 1);
|
|
158030
|
+
init_src6();
|
|
158031
|
+
debug21 = (0, import_debug21.default)("reactionary:medusa:client");
|
|
158032
|
+
SESSION_KEY2 = "MEDUSA_PROVIDER";
|
|
158033
|
+
RequestContextTokenStore2 = class {
|
|
158034
|
+
constructor(context2, keyPrefix = "__x") {
|
|
158035
|
+
this.context = context2;
|
|
158036
|
+
this.keyPrefix = keyPrefix;
|
|
158037
|
+
}
|
|
158038
|
+
context;
|
|
158039
|
+
keyPrefix;
|
|
158040
|
+
getItem(key) {
|
|
158041
|
+
if (this.context.session[SESSION_KEY2] === void 0) {
|
|
158042
|
+
this.context.session[SESSION_KEY2] = {};
|
|
158043
|
+
}
|
|
158044
|
+
const retVal = this.context.session[SESSION_KEY2] ? this.context.session[SESSION_KEY2][this.keyPrefix + "_" + key] || null : null;
|
|
158045
|
+
if (debug21.enabled) {
|
|
158046
|
+
debug21(
|
|
158047
|
+
`Getting token item for key: ${this.keyPrefix + "_" + key} - Found: ${retVal ? "Yes" : "No"}`
|
|
158048
|
+
);
|
|
158049
|
+
}
|
|
158050
|
+
return Promise.resolve(retVal);
|
|
158051
|
+
}
|
|
158052
|
+
setItem(key, value) {
|
|
158053
|
+
if (this.context.session[SESSION_KEY2] === void 0) {
|
|
158054
|
+
this.context.session[SESSION_KEY2] = {};
|
|
158055
|
+
}
|
|
158056
|
+
if (debug21.enabled) {
|
|
158057
|
+
debug21(
|
|
158058
|
+
`Setting token item for key: ${this.keyPrefix + "_" + key} - Value: <redacted, ${value.length} chars>`
|
|
158059
|
+
);
|
|
158060
|
+
}
|
|
158061
|
+
this.context.session[SESSION_KEY2][this.keyPrefix + "_" + key] = value;
|
|
158062
|
+
return Promise.resolve();
|
|
158063
|
+
}
|
|
158064
|
+
removeItem(key) {
|
|
158065
|
+
if (this.context.session[SESSION_KEY2] === void 0) {
|
|
158066
|
+
this.context.session[SESSION_KEY2] = {};
|
|
158067
|
+
}
|
|
158068
|
+
if (debug21.enabled) {
|
|
158069
|
+
debug21(`Removing token item for key: ${this.keyPrefix + "_" + key}`);
|
|
158070
|
+
}
|
|
158071
|
+
delete this.context.session[SESSION_KEY2][this.keyPrefix + "_" + key];
|
|
158072
|
+
return Promise.resolve();
|
|
158073
|
+
}
|
|
158074
|
+
};
|
|
158075
|
+
Medusa = class {
|
|
158076
|
+
client;
|
|
158077
|
+
admin;
|
|
158078
|
+
store;
|
|
158079
|
+
auth;
|
|
158080
|
+
constructor(config3) {
|
|
158081
|
+
this.client = new Client(config3);
|
|
158082
|
+
this.admin = new Admin(this.client);
|
|
158083
|
+
this.store = new Store2(this.client);
|
|
158084
|
+
this.auth = new Auth(this.client, config3);
|
|
158085
|
+
}
|
|
158086
|
+
};
|
|
158087
|
+
MedusaAdminAPI = class {
|
|
158088
|
+
config;
|
|
158089
|
+
client;
|
|
158090
|
+
context;
|
|
158091
|
+
constructor(config3, context2) {
|
|
158092
|
+
this.config = config3;
|
|
158093
|
+
this.context = context2;
|
|
158094
|
+
this.client = new Medusa({
|
|
158095
|
+
baseUrl: this.config.apiUrl,
|
|
158096
|
+
apiKey: this.config.adminApiKey,
|
|
158097
|
+
debug: debug21.enabled,
|
|
158098
|
+
globalHeaders: {
|
|
158099
|
+
"x-medusa-locale": this.context.languageContext.locale
|
|
158100
|
+
}
|
|
158101
|
+
});
|
|
158102
|
+
}
|
|
158103
|
+
async getClient() {
|
|
158104
|
+
return this.client;
|
|
158105
|
+
}
|
|
158106
|
+
};
|
|
158107
|
+
MedusaAPI = class {
|
|
158108
|
+
config;
|
|
158109
|
+
client;
|
|
158110
|
+
context;
|
|
158111
|
+
constructor(config3, context2) {
|
|
158112
|
+
this.config = config3;
|
|
158113
|
+
this.context = context2;
|
|
158114
|
+
this.client = void 0;
|
|
158115
|
+
}
|
|
158116
|
+
async getActiveRegion() {
|
|
158117
|
+
const session = this.getSessionData();
|
|
158118
|
+
if (session.selectedRegion) {
|
|
158119
|
+
if (session.selectedRegion.currency_code === this.context.languageContext.currencyCode.toLowerCase()) {
|
|
158120
|
+
return session.selectedRegion;
|
|
158121
|
+
}
|
|
158122
|
+
}
|
|
158123
|
+
const regions = await (await this.getClient()).store.region.list();
|
|
158124
|
+
const allRegions = [];
|
|
158125
|
+
for (const region of regions.regions) {
|
|
158126
|
+
allRegions.push({
|
|
158127
|
+
id: region.id,
|
|
158128
|
+
name: region.name,
|
|
158129
|
+
currency_code: region.currency_code
|
|
158130
|
+
});
|
|
158131
|
+
}
|
|
158132
|
+
const selectedRegion = allRegions.find(
|
|
158133
|
+
(r3) => r3.currency_code === this.context.languageContext.currencyCode.toLowerCase()
|
|
158134
|
+
) || allRegions[0];
|
|
158135
|
+
this.context.languageContext.currencyCode = (selectedRegion || allRegions[0]).currency_code.toUpperCase();
|
|
158136
|
+
this.setSessionData({
|
|
158137
|
+
allRegions,
|
|
158138
|
+
selectedRegion
|
|
158139
|
+
});
|
|
158140
|
+
return selectedRegion;
|
|
158141
|
+
}
|
|
158142
|
+
async getClient() {
|
|
158143
|
+
if (!this.client) {
|
|
158144
|
+
this.client = this.createAuthenticatedClient(this.context);
|
|
158145
|
+
}
|
|
158146
|
+
return await this.client;
|
|
158147
|
+
}
|
|
158148
|
+
getSessionData() {
|
|
158149
|
+
return this.context.session[SESSION_KEY2] ? this.context.session[SESSION_KEY2] : MedusaSessionSchema.parse({});
|
|
158150
|
+
}
|
|
158151
|
+
setSessionData(sessionData) {
|
|
158152
|
+
const existingData = this.context.session[SESSION_KEY2];
|
|
158153
|
+
this.context.session[SESSION_KEY2] = {
|
|
158154
|
+
...existingData,
|
|
158155
|
+
...sessionData
|
|
158156
|
+
};
|
|
158157
|
+
}
|
|
158158
|
+
async register(email3, password, firstName, lastName, reqCtx) {
|
|
158159
|
+
try {
|
|
158160
|
+
const client = await this.getClient();
|
|
158161
|
+
const tokenResponse = await client.auth.register(
|
|
158162
|
+
"customer",
|
|
158163
|
+
"emailpass",
|
|
158164
|
+
{
|
|
158165
|
+
email: email3,
|
|
158166
|
+
password
|
|
158167
|
+
}
|
|
158168
|
+
);
|
|
158169
|
+
const customer = await client.store.customer.create({
|
|
158170
|
+
email: email3,
|
|
158171
|
+
first_name: firstName,
|
|
158172
|
+
last_name: lastName
|
|
158173
|
+
});
|
|
158174
|
+
const identity = await this.login(email3, password, reqCtx);
|
|
158175
|
+
return identity;
|
|
158176
|
+
} catch (error6) {
|
|
158177
|
+
debug21("Registration failed:", error6);
|
|
158178
|
+
throw new Error(
|
|
158179
|
+
`Registration failed: ${error6 instanceof Error ? error6.message : "Unknown error"}`
|
|
158180
|
+
);
|
|
158181
|
+
}
|
|
158182
|
+
}
|
|
158183
|
+
async login(email3, password, reqCtx) {
|
|
158184
|
+
try {
|
|
158185
|
+
const client = await this.getClient();
|
|
158186
|
+
const authResult = await client.auth.login("customer", "emailpass", {
|
|
158187
|
+
email: email3,
|
|
158188
|
+
password
|
|
158189
|
+
});
|
|
158190
|
+
if (typeof authResult === "string") {
|
|
158191
|
+
const token = authResult;
|
|
158192
|
+
if (token) {
|
|
158193
|
+
await client.client.setToken(token);
|
|
158194
|
+
}
|
|
158195
|
+
}
|
|
158196
|
+
const customerResponse = await client.store.customer.retrieve();
|
|
158197
|
+
if (customerResponse.customer) {
|
|
158198
|
+
const identity = {
|
|
158199
|
+
id: {
|
|
158200
|
+
userId: customerResponse.customer.id
|
|
158201
|
+
},
|
|
158202
|
+
type: "Registered"
|
|
158203
|
+
};
|
|
158204
|
+
return identity;
|
|
158205
|
+
}
|
|
158206
|
+
return {
|
|
158207
|
+
type: "Anonymous"
|
|
158208
|
+
};
|
|
158209
|
+
} catch (error6) {
|
|
158210
|
+
debug21("Login failed:", error6);
|
|
158211
|
+
throw new Error(
|
|
158212
|
+
`Login failed: ${error6 instanceof Error ? error6.message : "Unknown error"}`
|
|
158213
|
+
);
|
|
158214
|
+
}
|
|
158215
|
+
}
|
|
158216
|
+
async logout(reqCtx) {
|
|
158217
|
+
const identity = {
|
|
158218
|
+
type: "Anonymous"
|
|
158219
|
+
};
|
|
158220
|
+
const client = await this.getClient();
|
|
158221
|
+
try {
|
|
158222
|
+
await client.auth.logout();
|
|
158223
|
+
await client.client.clearToken();
|
|
158224
|
+
return identity;
|
|
158225
|
+
} catch (error6) {
|
|
158226
|
+
debug21("Logout failed:", error6);
|
|
158227
|
+
await client.client.clearToken();
|
|
158228
|
+
return identity;
|
|
158229
|
+
}
|
|
158230
|
+
}
|
|
158231
|
+
async createAuthenticatedClient(reqCtx) {
|
|
158232
|
+
const tokenStore = new RequestContextTokenStore2(reqCtx);
|
|
158233
|
+
const authenticatedClient = new Medusa({
|
|
158234
|
+
baseUrl: this.config.apiUrl,
|
|
158235
|
+
publishableKey: this.config.publishable_key,
|
|
158236
|
+
debug: debug21.enabled,
|
|
158237
|
+
globalHeaders: {
|
|
158238
|
+
"x-medusa-locale": this.context.languageContext.locale
|
|
158239
|
+
},
|
|
158240
|
+
auth: {
|
|
158241
|
+
type: "jwt",
|
|
158242
|
+
jwtTokenStorageMethod: "custom",
|
|
158243
|
+
storage: tokenStore
|
|
158244
|
+
}
|
|
158245
|
+
});
|
|
158246
|
+
return authenticatedClient;
|
|
158247
|
+
}
|
|
158248
|
+
};
|
|
158249
|
+
}
|
|
158250
|
+
});
|
|
158251
|
+
|
|
158020
158252
|
// packages/medusa/src/utils/medusa-helpers.ts
|
|
158021
158253
|
function isNotFoundFetchError(error6) {
|
|
158022
158254
|
return error6 instanceof FetchError && error6.status === 404;
|
|
@@ -158079,8 +158311,8 @@ function parseMedusaItemPrice(remoteItem, currency) {
|
|
|
158079
158311
|
};
|
|
158080
158312
|
}
|
|
158081
158313
|
function handleProviderError(action, error6) {
|
|
158082
|
-
if (
|
|
158083
|
-
|
|
158314
|
+
if (debug22.enabled) {
|
|
158315
|
+
debug22(`Failed to ${action}:`, error6);
|
|
158084
158316
|
}
|
|
158085
158317
|
throw new Error(
|
|
158086
158318
|
`Failed to ${action}: ${error6 instanceof Error ? error6.message : "Unknown error"}`
|
|
@@ -158098,27 +158330,29 @@ function safeStringConvert(val, defaultValue) {
|
|
|
158098
158330
|
}
|
|
158099
158331
|
return String(val);
|
|
158100
158332
|
}
|
|
158101
|
-
var
|
|
158333
|
+
var import_debug22, debug22;
|
|
158102
158334
|
var init_medusa_helpers = __esm({
|
|
158103
158335
|
"packages/medusa/src/utils/medusa-helpers.ts"() {
|
|
158104
158336
|
"use strict";
|
|
158105
158337
|
init_esm2();
|
|
158106
|
-
|
|
158107
|
-
|
|
158338
|
+
import_debug22 = __toESM(require_src(), 1);
|
|
158339
|
+
debug22 = (0, import_debug22.default)("reactionary:medusa:helpers");
|
|
158108
158340
|
}
|
|
158109
158341
|
});
|
|
158110
158342
|
|
|
158111
158343
|
// packages/medusa/src/capabilities/cart.capability.ts
|
|
158112
|
-
var import_types11,
|
|
158344
|
+
var import_types11, import_debug23, debug23, MedusaCartCapability;
|
|
158113
158345
|
var init_cart_capability5 = __esm({
|
|
158114
158346
|
"packages/medusa/src/capabilities/cart.capability.ts"() {
|
|
158115
158347
|
"use strict";
|
|
158116
158348
|
init_src();
|
|
158117
158349
|
init_esm2();
|
|
158118
158350
|
import_types11 = __toESM(require_dist3(), 1);
|
|
158119
|
-
|
|
158351
|
+
import_debug23 = __toESM(require_src(), 1);
|
|
158352
|
+
init_client6();
|
|
158353
|
+
init_medusa_schema();
|
|
158120
158354
|
init_medusa_helpers();
|
|
158121
|
-
|
|
158355
|
+
debug23 = (0, import_debug23.default)("reactionary:medusa:cart");
|
|
158122
158356
|
MedusaCartCapability = class extends CartCapability {
|
|
158123
158357
|
constructor(config3, cache, context2, medusaApi, factory) {
|
|
158124
158358
|
super(cache, context2);
|
|
@@ -158136,49 +158370,169 @@ var init_cart_capability5 = __esm({
|
|
|
158136
158370
|
* example: this.includedFields = [includedFields, '+discounts.*'].join(',');
|
|
158137
158371
|
*/
|
|
158138
158372
|
includedFields = ["+items.*", "+items.adjustments.*", "+shipping_methods.adjustments.*"].join(",");
|
|
158373
|
+
/**
|
|
158374
|
+
* Fields requested when listing owned carts, both via the cart-ownership
|
|
158375
|
+
* endpoint and via the session-tracked fallback. Every entry must be in
|
|
158376
|
+
* the allowed field set of both routes; `customer.id` stands in for
|
|
158377
|
+
* `customer_id`, which is not an allowed field (see normalizeOwnedCart).
|
|
158378
|
+
*/
|
|
158379
|
+
ownedCartListFields = ["id", "updated_at", "metadata", "items.id", "customer.id"].join(",");
|
|
158380
|
+
/** Sort order for the server-side owned-carts listing. */
|
|
158381
|
+
ownedCartListOrder = "-updated_at";
|
|
158382
|
+
/**
|
|
158383
|
+
* Package name of the optional backend plugin that serves
|
|
158384
|
+
* `GET /store/customers/me/carts` (a logged-in customer's open carts).
|
|
158385
|
+
*/
|
|
158386
|
+
cartOwnershipPluginName = "@solteq-excom/medusa-cart-ownership";
|
|
158387
|
+
/**
|
|
158388
|
+
* How long a backend's plugin list stays cached. Bounds how late a newly
|
|
158389
|
+
* (un)installed cart-ownership plugin is noticed.
|
|
158390
|
+
*/
|
|
158391
|
+
pluginDetectionTtlSeconds = 900;
|
|
158139
158392
|
async listCarts(payload) {
|
|
158140
|
-
|
|
158141
|
-
|
|
158142
|
-
|
|
158143
|
-
const totalCount = cartCollection ? cartCollection.length : 0;
|
|
158144
|
-
if (cartCollection) {
|
|
158145
|
-
cartCollection = cartCollection.slice((payload.search.paginationOptions.pageNumber - 1) * payload.search.paginationOptions.pageSize, payload.search.paginationOptions.pageNumber * payload.search.paginationOptions.pageSize);
|
|
158146
|
-
} else {
|
|
158147
|
-
cartCollection = [];
|
|
158393
|
+
let data = null;
|
|
158394
|
+
if (await this.shouldUseOwnershipEndpoint(payload)) {
|
|
158395
|
+
data = await this.listCartsViaOwnershipEndpoint(payload);
|
|
158148
158396
|
}
|
|
158149
|
-
|
|
158150
|
-
|
|
158151
|
-
const responses = await Promise.all(allPromises);
|
|
158152
|
-
const carts = responses.map((response) => response.cart).filter((cart) => !!cart);
|
|
158153
|
-
return success(this.factory.parseCartPaginatedSearchResult(
|
|
158154
|
-
this.context,
|
|
158155
|
-
{
|
|
158156
|
-
items: carts,
|
|
158157
|
-
totalCount
|
|
158158
|
-
},
|
|
158159
|
-
payload
|
|
158160
|
-
));
|
|
158397
|
+
data ??= await this.listCartsFromSession(payload);
|
|
158398
|
+
return success(this.factory.parseCartPaginatedSearchResult(this.context, data, payload));
|
|
158161
158399
|
}
|
|
158162
|
-
|
|
158163
|
-
|
|
158164
|
-
|
|
158165
|
-
|
|
158166
|
-
|
|
158167
|
-
|
|
158168
|
-
|
|
158169
|
-
|
|
158170
|
-
|
|
158171
|
-
|
|
158172
|
-
|
|
158173
|
-
|
|
158174
|
-
|
|
158175
|
-
|
|
158176
|
-
|
|
158177
|
-
|
|
158400
|
+
/**
|
|
158401
|
+
* The server-side owned-carts listing only applies to a logged-in
|
|
158402
|
+
* customer's own carts: a company bucket and anonymous/guest carts are
|
|
158403
|
+
* only known to the session, and the backend only serves the route when
|
|
158404
|
+
* the cart-ownership plugin is installed.
|
|
158405
|
+
*/
|
|
158406
|
+
async shouldUseOwnershipEndpoint(payload) {
|
|
158407
|
+
if (payload.search.company) {
|
|
158408
|
+
return false;
|
|
158409
|
+
}
|
|
158410
|
+
if (this.context.session.identityContext.identity.type !== "Registered") {
|
|
158411
|
+
return false;
|
|
158412
|
+
}
|
|
158413
|
+
return await this.isCartOwnershipPluginEnabled();
|
|
158414
|
+
}
|
|
158415
|
+
/**
|
|
158416
|
+
* Lists the customer's open carts through the cart-ownership plugin's
|
|
158417
|
+
* `GET /store/customers/me/carts`. Returns null when the backend turns
|
|
158418
|
+
* out not to serve the route after all (404: plugin configured but not
|
|
158419
|
+
* built; 401: the token is no longer valid), so the caller falls back to
|
|
158420
|
+
* the session-tracked list. Other errors are real backend faults and
|
|
158421
|
+
* propagate.
|
|
158422
|
+
*/
|
|
158423
|
+
async listCartsViaOwnershipEndpoint(payload) {
|
|
158424
|
+
const client = await this.getClient();
|
|
158425
|
+
const { pageNumber, pageSize } = payload.search.paginationOptions;
|
|
158426
|
+
try {
|
|
158427
|
+
const response = await client.client.fetch("/store/customers/me/carts", {
|
|
158428
|
+
method: "GET",
|
|
158429
|
+
query: {
|
|
158430
|
+
fields: this.ownedCartListFields,
|
|
158431
|
+
limit: pageSize,
|
|
158432
|
+
offset: (pageNumber - 1) * pageSize,
|
|
158433
|
+
order: this.ownedCartListOrder
|
|
158434
|
+
}
|
|
158435
|
+
});
|
|
158436
|
+
return {
|
|
158437
|
+
items: response.carts.map((cart) => this.normalizeOwnedCart(cart)),
|
|
158438
|
+
totalCount: response.count
|
|
158439
|
+
};
|
|
158440
|
+
} catch (err) {
|
|
158441
|
+
if (this.shouldFallBackToSessionList(err)) {
|
|
158442
|
+
debug23("Owned-carts endpoint unavailable, falling back to session-tracked carts:", err);
|
|
158443
|
+
return null;
|
|
158444
|
+
}
|
|
158445
|
+
throw err;
|
|
158446
|
+
}
|
|
158447
|
+
}
|
|
158448
|
+
/**
|
|
158449
|
+
* Lists carts from the ids tracked in the session: the behavior from
|
|
158450
|
+
* before the cart-ownership plugin existed, and still the only source for
|
|
158451
|
+
* anonymous/guest carts and company buckets.
|
|
158452
|
+
*/
|
|
158453
|
+
async listCartsFromSession(payload) {
|
|
158454
|
+
const client = await this.getClient();
|
|
158455
|
+
const sessionData = this.medusaApi.getSessionData();
|
|
158456
|
+
let cartCollection = payload.search.company ? sessionData.allOwnedCarts?.[payload.search.company.taxIdentifier] : sessionData.allOwnedCarts?.["_me"];
|
|
158457
|
+
const totalCount = cartCollection ? cartCollection.length : 0;
|
|
158458
|
+
if (cartCollection) {
|
|
158459
|
+
cartCollection = cartCollection.slice((payload.search.paginationOptions.pageNumber - 1) * payload.search.paginationOptions.pageSize, payload.search.paginationOptions.pageNumber * payload.search.paginationOptions.pageSize);
|
|
158460
|
+
} else {
|
|
158461
|
+
cartCollection = [];
|
|
158462
|
+
}
|
|
158463
|
+
const allPromises = cartCollection.map((cartIdentifier) => client.store.cart.retrieve(cartIdentifier.key, { fields: this.ownedCartListFields }));
|
|
158464
|
+
const responses = await Promise.all(allPromises);
|
|
158465
|
+
const carts = responses.map((response) => response.cart).filter((cart) => !!cart);
|
|
158466
|
+
return {
|
|
158467
|
+
items: carts.map((cart) => this.normalizeOwnedCart(cart)),
|
|
158468
|
+
totalCount
|
|
158469
|
+
};
|
|
158470
|
+
}
|
|
158471
|
+
/**
|
|
158472
|
+
* The factory reads `customer_id`, but only the `customer.id` relation is
|
|
158473
|
+
* an allowed list field, so copy it over when `customer_id` itself wasn't
|
|
158474
|
+
* returned.
|
|
158475
|
+
*/
|
|
158476
|
+
normalizeOwnedCart(cart) {
|
|
158477
|
+
return { ...cart, customer_id: cart.customer_id ?? cart.customer?.id };
|
|
158478
|
+
}
|
|
158479
|
+
/** A 404 (route not served) or 401 (token no longer valid) degrades to the session list. */
|
|
158480
|
+
shouldFallBackToSessionList(err) {
|
|
158481
|
+
return err instanceof FetchError && (err.status === 404 || err.status === 401);
|
|
158482
|
+
}
|
|
158483
|
+
/**
|
|
158484
|
+
* Checks whether the backend has the cart-ownership plugin, by its name in
|
|
158485
|
+
* core's `GET /admin/plugins`. Detection must never break cart listing, so
|
|
158486
|
+
* any failure just reports the plugin as absent.
|
|
158487
|
+
*/
|
|
158488
|
+
async isCartOwnershipPluginEnabled() {
|
|
158489
|
+
const plugins = await this.fetchEnabledPlugins();
|
|
158490
|
+
return plugins.includes(this.cartOwnershipPluginName);
|
|
158491
|
+
}
|
|
158492
|
+
/**
|
|
158493
|
+
* The backend's configured plugin list, kept in the reactionary cache
|
|
158494
|
+
* (shared across sessions) so not every request re-asks the admin API.
|
|
158495
|
+
* Failures are not cached: a plugin-less answer from here only costs the
|
|
158496
|
+
* fallback behavior, while caching a transient failure would hide the
|
|
158497
|
+
* plugin for a whole TTL.
|
|
158498
|
+
*/
|
|
158499
|
+
async fetchEnabledPlugins() {
|
|
158500
|
+
const cacheKey = `medusa:plugins:${this.config.apiUrl}`;
|
|
158501
|
+
const cached2 = await this.cache.get(cacheKey, MedusaCachedPluginListSchema);
|
|
158502
|
+
if (cached2) {
|
|
158503
|
+
return cached2.plugins;
|
|
158504
|
+
}
|
|
158505
|
+
try {
|
|
158506
|
+
const adminClient = await new MedusaAdminAPI(this.config, this.context).getClient();
|
|
158507
|
+
const response = await adminClient.client.fetch("/admin/plugins", { method: "GET" });
|
|
158508
|
+
const plugins = response.plugins.map((plugin) => plugin.name);
|
|
158509
|
+
await this.cache.put(cacheKey, { plugins }, { ttlSeconds: this.pluginDetectionTtlSeconds, dependencyIds: [] });
|
|
158510
|
+
return plugins;
|
|
158511
|
+
} catch (err) {
|
|
158512
|
+
debug23("Failed to list backend plugins:", err);
|
|
158513
|
+
return [];
|
|
158514
|
+
}
|
|
158515
|
+
}
|
|
158516
|
+
async getById(payload) {
|
|
158517
|
+
try {
|
|
158518
|
+
const client = await this.getClient();
|
|
158519
|
+
const medusaId = payload.cart;
|
|
158520
|
+
if (debug23.enabled) {
|
|
158521
|
+
debug23("Fetching cart by ID:", medusaId.key);
|
|
158522
|
+
}
|
|
158523
|
+
const cartResponse = await client.store.cart.retrieve(medusaId.key, { fields: this.includedFields });
|
|
158524
|
+
if (debug23.enabled) {
|
|
158525
|
+
debug23("Received cart response:", cartResponse);
|
|
158526
|
+
}
|
|
158527
|
+
if (cartResponse.cart) {
|
|
158528
|
+
return success(this.factory.parseCart(this.context, cartResponse.cart));
|
|
158529
|
+
}
|
|
158530
|
+
return error2({
|
|
158531
|
+
type: "NotFound",
|
|
158178
158532
|
identifier: payload
|
|
158179
158533
|
});
|
|
158180
158534
|
} catch (err) {
|
|
158181
|
-
|
|
158535
|
+
debug23("Failed to get cart by ID:", err);
|
|
158182
158536
|
return error2({
|
|
158183
158537
|
type: "NotFound",
|
|
158184
158538
|
identifier: payload
|
|
@@ -158209,8 +158563,8 @@ var init_cart_capability5 = __esm({
|
|
|
158209
158563
|
});
|
|
158210
158564
|
}
|
|
158211
158565
|
const medusaId = cartIdentifier;
|
|
158212
|
-
if (
|
|
158213
|
-
|
|
158566
|
+
if (debug23.enabled) {
|
|
158567
|
+
debug23(
|
|
158214
158568
|
"Adding item to cart ID:",
|
|
158215
158569
|
medusaId.key,
|
|
158216
158570
|
"SKU:",
|
|
@@ -158247,8 +158601,8 @@ var init_cart_capability5 = __esm({
|
|
|
158247
158601
|
fields: this.includedFields
|
|
158248
158602
|
}
|
|
158249
158603
|
);
|
|
158250
|
-
if (
|
|
158251
|
-
|
|
158604
|
+
if (debug23.enabled) {
|
|
158605
|
+
debug23("Received add item response:", response);
|
|
158252
158606
|
}
|
|
158253
158607
|
if (response.cart) {
|
|
158254
158608
|
return success(this.factory.parseCart(this.context, response.cart));
|
|
@@ -158303,6 +158657,21 @@ var init_cart_capability5 = __esm({
|
|
|
158303
158657
|
}
|
|
158304
158658
|
};
|
|
158305
158659
|
}
|
|
158660
|
+
/**
|
|
158661
|
+
* Session tracking is skipped for a logged-in customer's own carts when
|
|
158662
|
+
* the backend has the cart-ownership plugin: the backend attributes the
|
|
158663
|
+
* cart to the customer at creation and lists it server-side. Anonymous
|
|
158664
|
+
* carts and company buckets are still only known to the session.
|
|
158665
|
+
*/
|
|
158666
|
+
async shouldTrackOwnedCartInSession(payload) {
|
|
158667
|
+
if (payload.company) {
|
|
158668
|
+
return true;
|
|
158669
|
+
}
|
|
158670
|
+
if (this.context.session.identityContext.identity.type !== "Registered") {
|
|
158671
|
+
return true;
|
|
158672
|
+
}
|
|
158673
|
+
return !await this.isCartOwnershipPluginEnabled();
|
|
158674
|
+
}
|
|
158306
158675
|
addCartToOwnedList(cartIdentifier, companyId) {
|
|
158307
158676
|
const sessionData = this.medusaApi.getSessionData();
|
|
158308
158677
|
const companyIdToUse = companyId ? companyId.taxIdentifier : "_me";
|
|
@@ -158362,7 +158731,9 @@ var init_cart_capability5 = __esm({
|
|
|
158362
158731
|
}
|
|
158363
158732
|
);
|
|
158364
158733
|
if (response.cart) {
|
|
158365
|
-
|
|
158734
|
+
if (await this.shouldTrackOwnedCartInSession(payload)) {
|
|
158735
|
+
this.addCartToOwnedList(this.factory.parseCartIdentifier(this.context, response.cart), payload.company);
|
|
158736
|
+
}
|
|
158366
158737
|
this.medusaApi.setSessionData({
|
|
158367
158738
|
activeCartId: this.factory.parseCartIdentifier(this.context, response.cart)
|
|
158368
158739
|
});
|
|
@@ -158461,7 +158832,7 @@ var init_cart_capability5 = __esm({
|
|
|
158461
158832
|
identifier: void 0
|
|
158462
158833
|
});
|
|
158463
158834
|
} catch (err) {
|
|
158464
|
-
|
|
158835
|
+
debug23("Failed to get active cart ID:", err);
|
|
158465
158836
|
return error2({
|
|
158466
158837
|
type: "NotFound",
|
|
158467
158838
|
identifier: void 0
|
|
@@ -158833,15 +159204,15 @@ var init_category_capability5 = __esm({
|
|
|
158833
159204
|
});
|
|
158834
159205
|
|
|
158835
159206
|
// packages/medusa/src/capabilities/checkout.capability.ts
|
|
158836
|
-
var
|
|
159207
|
+
var import_debug24, debug24, CheckoutNotReadyForFinalizationError3, MedusaCheckoutCapability;
|
|
158837
159208
|
var init_checkout_capability5 = __esm({
|
|
158838
159209
|
"packages/medusa/src/capabilities/checkout.capability.ts"() {
|
|
158839
159210
|
"use strict";
|
|
158840
159211
|
init_src();
|
|
158841
|
-
|
|
159212
|
+
import_debug24 = __toESM(require_src(), 1);
|
|
158842
159213
|
init_zod();
|
|
158843
159214
|
init_medusa_helpers();
|
|
158844
|
-
|
|
159215
|
+
debug24 = (0, import_debug24.default)("reactionary:medusa:checkout");
|
|
158845
159216
|
CheckoutNotReadyForFinalizationError3 = class extends Error {
|
|
158846
159217
|
constructor(checkoutIdentifier) {
|
|
158847
159218
|
super(
|
|
@@ -158881,8 +159252,8 @@ var init_checkout_capability5 = __esm({
|
|
|
158881
159252
|
}
|
|
158882
159253
|
async initiateCheckoutForCart(payload) {
|
|
158883
159254
|
const client = await this.medusaApi.getClient();
|
|
158884
|
-
if (
|
|
158885
|
-
|
|
159255
|
+
if (debug24.enabled) {
|
|
159256
|
+
debug24(
|
|
158886
159257
|
`Initiating checkout for cart with key: ${payload.cart.identifier.key}`
|
|
158887
159258
|
);
|
|
158888
159259
|
}
|
|
@@ -158951,8 +159322,8 @@ var init_checkout_capability5 = __esm({
|
|
|
158951
159322
|
}
|
|
158952
159323
|
async getAvailableShippingMethods(payload) {
|
|
158953
159324
|
const client = await this.medusaApi.getClient();
|
|
158954
|
-
if (
|
|
158955
|
-
|
|
159325
|
+
if (debug24.enabled) {
|
|
159326
|
+
debug24(
|
|
158956
159327
|
`Fetching available shipping methods for checkout with key: ${payload.checkout.key}`
|
|
158957
159328
|
);
|
|
158958
159329
|
}
|
|
@@ -158960,8 +159331,8 @@ var init_checkout_capability5 = __esm({
|
|
|
158960
159331
|
this.getAvailableShippingMethodsPayload(payload)
|
|
158961
159332
|
);
|
|
158962
159333
|
const shippingMethods = [];
|
|
158963
|
-
if (
|
|
158964
|
-
|
|
159334
|
+
if (debug24.enabled) {
|
|
159335
|
+
debug24(
|
|
158965
159336
|
`Found ${shippingMethodResponse.shipping_options.length} shipping methods for checkout with key: ${payload.checkout.key}`,
|
|
158966
159337
|
shippingMethodResponse.shipping_options
|
|
158967
159338
|
);
|
|
@@ -158973,13 +159344,13 @@ var init_checkout_capability5 = __esm({
|
|
|
158973
159344
|
sm.calculated_price = updatedSM.shipping_option.calculated_price;
|
|
158974
159345
|
});
|
|
158975
159346
|
if (calculatedPricesPromises.length > 0) {
|
|
158976
|
-
if (
|
|
158977
|
-
|
|
159347
|
+
if (debug24.enabled) {
|
|
159348
|
+
debug24("Calculating prices for {0} shipping methods for checkout with key: {1}", [calculatedPricesPromises.length, payload.checkout.key]);
|
|
158978
159349
|
}
|
|
158979
159350
|
await Promise.all(calculatedPricesPromises);
|
|
158980
|
-
if (
|
|
158981
|
-
|
|
158982
|
-
|
|
159351
|
+
if (debug24.enabled) {
|
|
159352
|
+
debug24("Finished calculating prices for {0} shipping methods for checkout with key: {1}", [calculatedPricesPromises.length, payload.checkout.key]);
|
|
159353
|
+
debug24(`Updated shipping methods for checkout with key: ${payload.checkout.key}`, shippingMethodResponse.shipping_options);
|
|
158983
159354
|
}
|
|
158984
159355
|
}
|
|
158985
159356
|
for (const sm of shippingMethodResponse.shipping_options) {
|
|
@@ -158989,8 +159360,8 @@ var init_checkout_capability5 = __esm({
|
|
|
158989
159360
|
}
|
|
158990
159361
|
shippingMethods.push(this.factory.parseShippingMethod(this.context, sm));
|
|
158991
159362
|
}
|
|
158992
|
-
if (
|
|
158993
|
-
|
|
159363
|
+
if (debug24.enabled) {
|
|
159364
|
+
debug24(
|
|
158994
159365
|
`Found ${shippingMethods.length} shipping methods for checkout with key: ${payload.checkout.key}`,
|
|
158995
159366
|
shippingMethods
|
|
158996
159367
|
);
|
|
@@ -159006,8 +159377,8 @@ var init_checkout_capability5 = __esm({
|
|
|
159006
159377
|
}
|
|
159007
159378
|
async getAvailablePaymentMethods(payload) {
|
|
159008
159379
|
const client = await this.medusaApi.getClient();
|
|
159009
|
-
if (
|
|
159010
|
-
|
|
159380
|
+
if (debug24.enabled) {
|
|
159381
|
+
debug24(
|
|
159011
159382
|
`Fetching available payment methods for checkout with key: ${payload.checkout.key}`
|
|
159012
159383
|
);
|
|
159013
159384
|
}
|
|
@@ -159023,8 +159394,8 @@ var init_checkout_capability5 = __esm({
|
|
|
159023
159394
|
const payMethod = this.factory.parsePaymentMethod(this.context, pm);
|
|
159024
159395
|
paymentMethods.push(payMethod);
|
|
159025
159396
|
}
|
|
159026
|
-
if (
|
|
159027
|
-
|
|
159397
|
+
if (debug24.enabled) {
|
|
159398
|
+
debug24(
|
|
159028
159399
|
`Found ${paymentMethods.length} payment methods for checkout with key: ${payload.checkout.key}`,
|
|
159029
159400
|
paymentMethods
|
|
159030
159401
|
);
|
|
@@ -159042,8 +159413,8 @@ var init_checkout_capability5 = __esm({
|
|
|
159042
159413
|
}
|
|
159043
159414
|
async addPaymentInstruction(payload) {
|
|
159044
159415
|
const client = await this.medusaApi.getClient();
|
|
159045
|
-
if (
|
|
159046
|
-
|
|
159416
|
+
if (debug24.enabled) {
|
|
159417
|
+
debug24(
|
|
159047
159418
|
`Adding payment instruction ${payload.paymentInstruction.paymentMethod.name} to checkout with key: ${payload.checkout.key}`
|
|
159048
159419
|
);
|
|
159049
159420
|
}
|
|
@@ -159060,7 +159431,7 @@ var init_checkout_capability5 = __esm({
|
|
|
159060
159431
|
);
|
|
159061
159432
|
return success(this.factory.parseCheckout(this.context, updatedCartResponse.cart));
|
|
159062
159433
|
} catch (error6) {
|
|
159063
|
-
|
|
159434
|
+
debug24("Failed to add payment instruction: {0}", [error6]);
|
|
159064
159435
|
throw new Error(
|
|
159065
159436
|
`Failed to add payment instruction: ${error6 instanceof Error ? error6.message : "Unknown error"}`
|
|
159066
159437
|
);
|
|
@@ -159216,15 +159587,15 @@ var init_checkout_capability5 = __esm({
|
|
|
159216
159587
|
});
|
|
159217
159588
|
|
|
159218
159589
|
// packages/medusa/src/capabilities/company.capability.ts
|
|
159219
|
-
var
|
|
159590
|
+
var import_debug25, debug25, MedusaCompanyCapability;
|
|
159220
159591
|
var init_company_capability3 = __esm({
|
|
159221
159592
|
"packages/medusa/src/capabilities/company.capability.ts"() {
|
|
159222
159593
|
"use strict";
|
|
159223
159594
|
init_esm2();
|
|
159224
159595
|
init_src();
|
|
159225
|
-
|
|
159596
|
+
import_debug25 = __toESM(require_src(), 1);
|
|
159226
159597
|
init_medusa_helpers();
|
|
159227
|
-
|
|
159598
|
+
debug25 = (0, import_debug25.default)("reactionary:medusa:company");
|
|
159228
159599
|
MedusaCompanyCapability = class extends CompanyCapability {
|
|
159229
159600
|
constructor(config3, cache, context2, medusaApi, factory) {
|
|
159230
159601
|
super(cache, context2);
|
|
@@ -159302,7 +159673,7 @@ var init_company_capability3 = __esm({
|
|
|
159302
159673
|
}
|
|
159303
159674
|
}
|
|
159304
159675
|
async listCompanies(payload) {
|
|
159305
|
-
|
|
159676
|
+
debug25("listCompanies", payload);
|
|
159306
159677
|
try {
|
|
159307
159678
|
const client = await this.medusaApi.getClient();
|
|
159308
159679
|
const response = await client.client.fetch("/store/customers/me/employees", { method: "GET" });
|
|
@@ -159325,7 +159696,7 @@ var init_company_capability3 = __esm({
|
|
|
159325
159696
|
}
|
|
159326
159697
|
}
|
|
159327
159698
|
async addShippingAddress(payload) {
|
|
159328
|
-
|
|
159699
|
+
debug25("addShippingAddress", payload);
|
|
159329
159700
|
try {
|
|
159330
159701
|
const company = await this.fetchCompanyByTaxIdentifier(payload.company.taxIdentifier);
|
|
159331
159702
|
if (!company) {
|
|
@@ -159350,7 +159721,7 @@ var init_company_capability3 = __esm({
|
|
|
159350
159721
|
}
|
|
159351
159722
|
}
|
|
159352
159723
|
async updateShippingAddress(payload) {
|
|
159353
|
-
|
|
159724
|
+
debug25("updateShippingAddress", payload);
|
|
159354
159725
|
try {
|
|
159355
159726
|
const company = await this.fetchCompanyByTaxIdentifier(payload.company.taxIdentifier);
|
|
159356
159727
|
if (!company) {
|
|
@@ -159372,7 +159743,7 @@ var init_company_capability3 = __esm({
|
|
|
159372
159743
|
}
|
|
159373
159744
|
}
|
|
159374
159745
|
async removeShippingAddress(payload) {
|
|
159375
|
-
|
|
159746
|
+
debug25("removeShippingAddress", payload);
|
|
159376
159747
|
try {
|
|
159377
159748
|
const company = await this.fetchCompanyByTaxIdentifier(payload.company.taxIdentifier);
|
|
159378
159749
|
if (!company) {
|
|
@@ -159393,7 +159764,7 @@ var init_company_capability3 = __esm({
|
|
|
159393
159764
|
}
|
|
159394
159765
|
}
|
|
159395
159766
|
async makeShippingAddressDefault(payload) {
|
|
159396
|
-
|
|
159767
|
+
debug25("makeShippingAddressDefault", payload);
|
|
159397
159768
|
try {
|
|
159398
159769
|
const company = await this.fetchCompanyByTaxIdentifier(payload.company.taxIdentifier);
|
|
159399
159770
|
if (!company) {
|
|
@@ -159455,15 +159826,15 @@ var init_company_capability3 = __esm({
|
|
|
159455
159826
|
});
|
|
159456
159827
|
|
|
159457
159828
|
// packages/medusa/src/capabilities/company-registration.capability.ts
|
|
159458
|
-
var
|
|
159829
|
+
var import_debug26, debug26, MedusaCompanyRegistrationCapability;
|
|
159459
159830
|
var init_company_registration_capability3 = __esm({
|
|
159460
159831
|
"packages/medusa/src/capabilities/company-registration.capability.ts"() {
|
|
159461
159832
|
"use strict";
|
|
159462
159833
|
init_esm2();
|
|
159463
159834
|
init_src();
|
|
159464
|
-
|
|
159835
|
+
import_debug26 = __toESM(require_src(), 1);
|
|
159465
159836
|
init_medusa_helpers();
|
|
159466
|
-
|
|
159837
|
+
debug26 = (0, import_debug26.default)("reactionary:medusa:company-registration");
|
|
159467
159838
|
MedusaCompanyRegistrationCapability = class extends CompanyRegistrationCapability {
|
|
159468
159839
|
constructor(config3, cache, context2, medusaApi, factory) {
|
|
159469
159840
|
super(cache, context2);
|
|
@@ -159503,7 +159874,7 @@ var init_company_registration_capability3 = __esm({
|
|
|
159503
159874
|
};
|
|
159504
159875
|
}
|
|
159505
159876
|
async requestRegistration(payload) {
|
|
159506
|
-
|
|
159877
|
+
debug26("requestRegistration", payload);
|
|
159507
159878
|
try {
|
|
159508
159879
|
const client = await this.medusaApi.getClient();
|
|
159509
159880
|
const createResponse = await client.client.fetch(
|
|
@@ -159530,7 +159901,7 @@ var init_company_registration_capability3 = __esm({
|
|
|
159530
159901
|
}
|
|
159531
159902
|
}
|
|
159532
159903
|
async checkRequestStatus(payload) {
|
|
159533
|
-
|
|
159904
|
+
debug26("checkRequestStatus", payload);
|
|
159534
159905
|
try {
|
|
159535
159906
|
const company = await this.fetchCompany(payload.requestIdentifier.key);
|
|
159536
159907
|
if (!company) {
|
|
@@ -159558,15 +159929,15 @@ var init_company_registration_capability3 = __esm({
|
|
|
159558
159929
|
});
|
|
159559
159930
|
|
|
159560
159931
|
// packages/medusa/src/capabilities/employee.capability.ts
|
|
159561
|
-
var
|
|
159932
|
+
var import_debug27, debug27, EMPLOYEE_FIELDS, MedusaEmployeeCapability;
|
|
159562
159933
|
var init_employee_capability3 = __esm({
|
|
159563
159934
|
"packages/medusa/src/capabilities/employee.capability.ts"() {
|
|
159564
159935
|
"use strict";
|
|
159565
159936
|
init_esm2();
|
|
159566
159937
|
init_src();
|
|
159567
|
-
|
|
159938
|
+
import_debug27 = __toESM(require_src(), 1);
|
|
159568
159939
|
init_medusa_helpers();
|
|
159569
|
-
|
|
159940
|
+
debug27 = (0, import_debug27.default)("reactionary:medusa:employee");
|
|
159570
159941
|
EMPLOYEE_FIELDS = ["*", "customer.*"].join(",");
|
|
159571
159942
|
MedusaEmployeeCapability = class extends EmployeeCapability {
|
|
159572
159943
|
constructor(config3, cache, context2, medusaApi, factory) {
|
|
@@ -159636,7 +160007,7 @@ var init_employee_capability3 = __esm({
|
|
|
159636
160007
|
return void 0;
|
|
159637
160008
|
}
|
|
159638
160009
|
async listEmployees(payload) {
|
|
159639
|
-
|
|
160010
|
+
debug27("listEmployees", payload);
|
|
159640
160011
|
try {
|
|
159641
160012
|
const companyId = await this.resolveCompanyId(payload.search.company.taxIdentifier);
|
|
159642
160013
|
if (!companyId) {
|
|
@@ -159679,7 +160050,7 @@ var init_employee_capability3 = __esm({
|
|
|
159679
160050
|
}
|
|
159680
160051
|
}
|
|
159681
160052
|
async getByEmail(payload) {
|
|
159682
|
-
|
|
160053
|
+
debug27("getByEmail", payload);
|
|
159683
160054
|
try {
|
|
159684
160055
|
const companyId = await this.resolveCompanyId(payload.company.taxIdentifier);
|
|
159685
160056
|
if (!companyId) {
|
|
@@ -159723,7 +160094,7 @@ var init_employee_capability3 = __esm({
|
|
|
159723
160094
|
);
|
|
159724
160095
|
}
|
|
159725
160096
|
async assignRole(payload) {
|
|
159726
|
-
|
|
160097
|
+
debug27("assignRole", payload);
|
|
159727
160098
|
try {
|
|
159728
160099
|
return await this.updateEmployeeRole(
|
|
159729
160100
|
payload.company,
|
|
@@ -159735,7 +160106,7 @@ var init_employee_capability3 = __esm({
|
|
|
159735
160106
|
}
|
|
159736
160107
|
}
|
|
159737
160108
|
async unassignRole(payload) {
|
|
159738
|
-
|
|
160109
|
+
debug27("unassignRole", payload);
|
|
159739
160110
|
try {
|
|
159740
160111
|
return await this.updateEmployeeRole(
|
|
159741
160112
|
payload.company,
|
|
@@ -159747,7 +160118,7 @@ var init_employee_capability3 = __esm({
|
|
|
159747
160118
|
}
|
|
159748
160119
|
}
|
|
159749
160120
|
async removeEmployee(payload) {
|
|
159750
|
-
|
|
160121
|
+
debug27("removeEmployee", payload);
|
|
159751
160122
|
try {
|
|
159752
160123
|
const companyId = await this.resolveCompanyId(payload.company.taxIdentifier);
|
|
159753
160124
|
if (!companyId) {
|
|
@@ -159886,16 +160257,16 @@ var init_employee_invitation_factory3 = __esm({
|
|
|
159886
160257
|
});
|
|
159887
160258
|
|
|
159888
160259
|
// packages/medusa/src/capabilities/employee-invitation.capability.ts
|
|
159889
|
-
var
|
|
160260
|
+
var import_debug28, debug28, EMPLOYEE_INVITATION_FIELDS, MedusaEmployeeInvitationCapability;
|
|
159890
160261
|
var init_employee_invitation_capability3 = __esm({
|
|
159891
160262
|
"packages/medusa/src/capabilities/employee-invitation.capability.ts"() {
|
|
159892
160263
|
"use strict";
|
|
159893
160264
|
init_esm2();
|
|
159894
160265
|
init_src();
|
|
159895
|
-
|
|
160266
|
+
import_debug28 = __toESM(require_src(), 1);
|
|
159896
160267
|
init_employee_invitation_factory3();
|
|
159897
160268
|
init_medusa_helpers();
|
|
159898
|
-
|
|
160269
|
+
debug28 = (0, import_debug28.default)("reactionary:medusa:employee-invitation");
|
|
159899
160270
|
EMPLOYEE_INVITATION_FIELDS = [
|
|
159900
160271
|
"id",
|
|
159901
160272
|
"email",
|
|
@@ -159952,7 +160323,7 @@ var init_employee_invitation_capability3 = __esm({
|
|
|
159952
160323
|
}
|
|
159953
160324
|
}
|
|
159954
160325
|
async inviteEmployee(payload) {
|
|
159955
|
-
|
|
160326
|
+
debug28("inviteEmployee", payload);
|
|
159956
160327
|
try {
|
|
159957
160328
|
const companyId = await this.resolveCompanyId(payload.company.taxIdentifier);
|
|
159958
160329
|
if (!companyId) {
|
|
@@ -159979,7 +160350,7 @@ var init_employee_invitation_capability3 = __esm({
|
|
|
159979
160350
|
}
|
|
159980
160351
|
}
|
|
159981
160352
|
async acceptInvitation(payload) {
|
|
159982
|
-
|
|
160353
|
+
debug28("acceptInvitation", { invitationIdentifier: payload.invitationIdentifier });
|
|
159983
160354
|
try {
|
|
159984
160355
|
const { invitationId } = parseInvitationKey(payload.invitationIdentifier.key);
|
|
159985
160356
|
const client = await this.medusaApi.getClient();
|
|
@@ -159999,7 +160370,7 @@ var init_employee_invitation_capability3 = __esm({
|
|
|
159999
160370
|
}
|
|
160000
160371
|
}
|
|
160001
160372
|
async revokeInvitation(payload) {
|
|
160002
|
-
|
|
160373
|
+
debug28("revokeInvitation", payload);
|
|
160003
160374
|
try {
|
|
160004
160375
|
const { companyId, invitationId } = parseInvitationKey(
|
|
160005
160376
|
payload.invitationIdentifier.key
|
|
@@ -160015,7 +160386,7 @@ var init_employee_invitation_capability3 = __esm({
|
|
|
160015
160386
|
}
|
|
160016
160387
|
}
|
|
160017
160388
|
async listInvitations(payload) {
|
|
160018
|
-
|
|
160389
|
+
debug28("listInvitations", payload);
|
|
160019
160390
|
try {
|
|
160020
160391
|
const client = await this.medusaApi.getClient();
|
|
160021
160392
|
const { pageNumber, pageSize } = payload.search.paginationOptions;
|
|
@@ -160088,13 +160459,13 @@ var init_employee_invitation_capability3 = __esm({
|
|
|
160088
160459
|
});
|
|
160089
160460
|
|
|
160090
160461
|
// packages/medusa/src/capabilities/identity.capability.ts
|
|
160091
|
-
var
|
|
160462
|
+
var import_debug29, debug29, MedusaIdentityCapability;
|
|
160092
160463
|
var init_identity_capability5 = __esm({
|
|
160093
160464
|
"packages/medusa/src/capabilities/identity.capability.ts"() {
|
|
160094
160465
|
"use strict";
|
|
160095
160466
|
init_src();
|
|
160096
|
-
|
|
160097
|
-
|
|
160467
|
+
import_debug29 = __toESM(require_src(), 1);
|
|
160468
|
+
debug29 = (0, import_debug29.default)("reactionary:medusa:identity");
|
|
160098
160469
|
MedusaIdentityCapability = class extends IdentityCapability {
|
|
160099
160470
|
config;
|
|
160100
160471
|
medusaApi;
|
|
@@ -160113,9 +160484,9 @@ var init_identity_capability5 = __esm({
|
|
|
160113
160484
|
const medusaClient = await this.medusaApi.getClient();
|
|
160114
160485
|
const token = await medusaClient.client.getToken();
|
|
160115
160486
|
if (!token) {
|
|
160116
|
-
|
|
160487
|
+
debug29("No active session token found, returning anonymous identity");
|
|
160117
160488
|
if (this.medusaApi.getSessionData().activeCartId) {
|
|
160118
|
-
|
|
160489
|
+
debug29("Active cart found in session without token, treating as guest session");
|
|
160119
160490
|
const identity3 = {
|
|
160120
160491
|
type: "Guest",
|
|
160121
160492
|
id: {
|
|
@@ -160131,7 +160502,7 @@ var init_identity_capability5 = __esm({
|
|
|
160131
160502
|
}
|
|
160132
160503
|
const customerResponse = await medusaClient.store.customer.retrieve();
|
|
160133
160504
|
if (customerResponse.customer) {
|
|
160134
|
-
|
|
160505
|
+
debug29("Customer authenticated:", customerResponse.customer.email);
|
|
160135
160506
|
const identity2 = {
|
|
160136
160507
|
id: {
|
|
160137
160508
|
userId: customerResponse.customer.id
|
|
@@ -160145,14 +160516,14 @@ var init_identity_capability5 = __esm({
|
|
|
160145
160516
|
this.updateIdentityContext(identity);
|
|
160146
160517
|
return success(identity);
|
|
160147
160518
|
} catch (error6) {
|
|
160148
|
-
|
|
160519
|
+
debug29("getSelf failed, returning anonymous identity:", error6);
|
|
160149
160520
|
const identity = this.createAnonymousIdentity();
|
|
160150
160521
|
this.updateIdentityContext(identity);
|
|
160151
160522
|
return success(identity);
|
|
160152
160523
|
}
|
|
160153
160524
|
}
|
|
160154
160525
|
async login(payload) {
|
|
160155
|
-
|
|
160526
|
+
debug29("Attempting login for user:", payload.username);
|
|
160156
160527
|
const identity = await this.medusaApi.login(
|
|
160157
160528
|
payload.username,
|
|
160158
160529
|
payload.password,
|
|
@@ -160162,13 +160533,13 @@ var init_identity_capability5 = __esm({
|
|
|
160162
160533
|
return success(identity);
|
|
160163
160534
|
}
|
|
160164
160535
|
async logout(_payload) {
|
|
160165
|
-
|
|
160536
|
+
debug29("Logging out user");
|
|
160166
160537
|
const identity = await this.medusaApi.logout(this.context);
|
|
160167
160538
|
this.updateIdentityContext(identity);
|
|
160168
160539
|
return success(identity);
|
|
160169
160540
|
}
|
|
160170
160541
|
async register(payload) {
|
|
160171
|
-
|
|
160542
|
+
debug29("Registering new user:", payload.username);
|
|
160172
160543
|
const nameParts = payload.username.split(".");
|
|
160173
160544
|
const firstName = nameParts[0] || "User";
|
|
160174
160545
|
const lastName = nameParts.slice(1).join(" ") || "Account";
|
|
@@ -160211,235 +160582,6 @@ var init_identity_capability5 = __esm({
|
|
|
160211
160582
|
}
|
|
160212
160583
|
});
|
|
160213
160584
|
|
|
160214
|
-
// packages/medusa/src/core/client.ts
|
|
160215
|
-
var import_debug29, debug29, SESSION_KEY2, RequestContextTokenStore2, Medusa, MedusaAdminAPI, MedusaAPI;
|
|
160216
|
-
var init_client6 = __esm({
|
|
160217
|
-
"packages/medusa/src/core/client.ts"() {
|
|
160218
|
-
"use strict";
|
|
160219
|
-
init_esm2();
|
|
160220
|
-
import_debug29 = __toESM(require_src(), 1);
|
|
160221
|
-
init_src6();
|
|
160222
|
-
debug29 = (0, import_debug29.default)("reactionary:medusa:client");
|
|
160223
|
-
SESSION_KEY2 = "MEDUSA_PROVIDER";
|
|
160224
|
-
RequestContextTokenStore2 = class {
|
|
160225
|
-
constructor(context2, keyPrefix = "__x") {
|
|
160226
|
-
this.context = context2;
|
|
160227
|
-
this.keyPrefix = keyPrefix;
|
|
160228
|
-
}
|
|
160229
|
-
context;
|
|
160230
|
-
keyPrefix;
|
|
160231
|
-
getItem(key) {
|
|
160232
|
-
if (this.context.session[SESSION_KEY2] === void 0) {
|
|
160233
|
-
this.context.session[SESSION_KEY2] = {};
|
|
160234
|
-
}
|
|
160235
|
-
const retVal = this.context.session[SESSION_KEY2] ? this.context.session[SESSION_KEY2][this.keyPrefix + "_" + key] || null : null;
|
|
160236
|
-
if (debug29.enabled) {
|
|
160237
|
-
debug29(
|
|
160238
|
-
`Getting token item for key: ${this.keyPrefix + "_" + key} - Found: ${retVal ? "Yes" : "No"}`
|
|
160239
|
-
);
|
|
160240
|
-
}
|
|
160241
|
-
return Promise.resolve(retVal);
|
|
160242
|
-
}
|
|
160243
|
-
setItem(key, value) {
|
|
160244
|
-
if (this.context.session[SESSION_KEY2] === void 0) {
|
|
160245
|
-
this.context.session[SESSION_KEY2] = {};
|
|
160246
|
-
}
|
|
160247
|
-
if (debug29.enabled) {
|
|
160248
|
-
debug29(
|
|
160249
|
-
`Setting token item for key: ${this.keyPrefix + "_" + key} - Value: <redacted, ${value.length} chars>`
|
|
160250
|
-
);
|
|
160251
|
-
}
|
|
160252
|
-
this.context.session[SESSION_KEY2][this.keyPrefix + "_" + key] = value;
|
|
160253
|
-
return Promise.resolve();
|
|
160254
|
-
}
|
|
160255
|
-
removeItem(key) {
|
|
160256
|
-
if (this.context.session[SESSION_KEY2] === void 0) {
|
|
160257
|
-
this.context.session[SESSION_KEY2] = {};
|
|
160258
|
-
}
|
|
160259
|
-
if (debug29.enabled) {
|
|
160260
|
-
debug29(`Removing token item for key: ${this.keyPrefix + "_" + key}`);
|
|
160261
|
-
}
|
|
160262
|
-
delete this.context.session[SESSION_KEY2][this.keyPrefix + "_" + key];
|
|
160263
|
-
return Promise.resolve();
|
|
160264
|
-
}
|
|
160265
|
-
};
|
|
160266
|
-
Medusa = class {
|
|
160267
|
-
client;
|
|
160268
|
-
admin;
|
|
160269
|
-
store;
|
|
160270
|
-
auth;
|
|
160271
|
-
constructor(config3) {
|
|
160272
|
-
this.client = new Client(config3);
|
|
160273
|
-
this.admin = new Admin(this.client);
|
|
160274
|
-
this.store = new Store2(this.client);
|
|
160275
|
-
this.auth = new Auth(this.client, config3);
|
|
160276
|
-
}
|
|
160277
|
-
};
|
|
160278
|
-
MedusaAdminAPI = class {
|
|
160279
|
-
config;
|
|
160280
|
-
client;
|
|
160281
|
-
context;
|
|
160282
|
-
constructor(config3, context2) {
|
|
160283
|
-
this.config = config3;
|
|
160284
|
-
this.context = context2;
|
|
160285
|
-
this.client = new Medusa({
|
|
160286
|
-
baseUrl: this.config.apiUrl,
|
|
160287
|
-
apiKey: this.config.adminApiKey,
|
|
160288
|
-
debug: debug29.enabled,
|
|
160289
|
-
globalHeaders: {
|
|
160290
|
-
"x-medusa-locale": this.context.languageContext.locale
|
|
160291
|
-
}
|
|
160292
|
-
});
|
|
160293
|
-
}
|
|
160294
|
-
async getClient() {
|
|
160295
|
-
return this.client;
|
|
160296
|
-
}
|
|
160297
|
-
};
|
|
160298
|
-
MedusaAPI = class {
|
|
160299
|
-
config;
|
|
160300
|
-
client;
|
|
160301
|
-
context;
|
|
160302
|
-
constructor(config3, context2) {
|
|
160303
|
-
this.config = config3;
|
|
160304
|
-
this.context = context2;
|
|
160305
|
-
this.client = void 0;
|
|
160306
|
-
}
|
|
160307
|
-
async getActiveRegion() {
|
|
160308
|
-
const session = this.getSessionData();
|
|
160309
|
-
if (session.selectedRegion) {
|
|
160310
|
-
if (session.selectedRegion.currency_code === this.context.languageContext.currencyCode.toLowerCase()) {
|
|
160311
|
-
return session.selectedRegion;
|
|
160312
|
-
}
|
|
160313
|
-
}
|
|
160314
|
-
const regions = await (await this.getClient()).store.region.list();
|
|
160315
|
-
const allRegions = [];
|
|
160316
|
-
for (const region of regions.regions) {
|
|
160317
|
-
allRegions.push({
|
|
160318
|
-
id: region.id,
|
|
160319
|
-
name: region.name,
|
|
160320
|
-
currency_code: region.currency_code
|
|
160321
|
-
});
|
|
160322
|
-
}
|
|
160323
|
-
const selectedRegion = allRegions.find(
|
|
160324
|
-
(r3) => r3.currency_code === this.context.languageContext.currencyCode.toLowerCase()
|
|
160325
|
-
) || allRegions[0];
|
|
160326
|
-
this.context.languageContext.currencyCode = (selectedRegion || allRegions[0]).currency_code.toUpperCase();
|
|
160327
|
-
this.setSessionData({
|
|
160328
|
-
allRegions,
|
|
160329
|
-
selectedRegion
|
|
160330
|
-
});
|
|
160331
|
-
return selectedRegion;
|
|
160332
|
-
}
|
|
160333
|
-
async getClient() {
|
|
160334
|
-
if (!this.client) {
|
|
160335
|
-
this.client = this.createAuthenticatedClient(this.context);
|
|
160336
|
-
}
|
|
160337
|
-
return await this.client;
|
|
160338
|
-
}
|
|
160339
|
-
getSessionData() {
|
|
160340
|
-
return this.context.session[SESSION_KEY2] ? this.context.session[SESSION_KEY2] : MedusaSessionSchema.parse({});
|
|
160341
|
-
}
|
|
160342
|
-
setSessionData(sessionData) {
|
|
160343
|
-
const existingData = this.context.session[SESSION_KEY2];
|
|
160344
|
-
this.context.session[SESSION_KEY2] = {
|
|
160345
|
-
...existingData,
|
|
160346
|
-
...sessionData
|
|
160347
|
-
};
|
|
160348
|
-
}
|
|
160349
|
-
async register(email3, password, firstName, lastName, reqCtx) {
|
|
160350
|
-
try {
|
|
160351
|
-
const client = await this.getClient();
|
|
160352
|
-
const tokenResponse = await client.auth.register(
|
|
160353
|
-
"customer",
|
|
160354
|
-
"emailpass",
|
|
160355
|
-
{
|
|
160356
|
-
email: email3,
|
|
160357
|
-
password
|
|
160358
|
-
}
|
|
160359
|
-
);
|
|
160360
|
-
const customer = await client.store.customer.create({
|
|
160361
|
-
email: email3,
|
|
160362
|
-
first_name: firstName,
|
|
160363
|
-
last_name: lastName
|
|
160364
|
-
});
|
|
160365
|
-
const identity = await this.login(email3, password, reqCtx);
|
|
160366
|
-
return identity;
|
|
160367
|
-
} catch (error6) {
|
|
160368
|
-
debug29("Registration failed:", error6);
|
|
160369
|
-
throw new Error(
|
|
160370
|
-
`Registration failed: ${error6 instanceof Error ? error6.message : "Unknown error"}`
|
|
160371
|
-
);
|
|
160372
|
-
}
|
|
160373
|
-
}
|
|
160374
|
-
async login(email3, password, reqCtx) {
|
|
160375
|
-
try {
|
|
160376
|
-
const client = await this.getClient();
|
|
160377
|
-
const authResult = await client.auth.login("customer", "emailpass", {
|
|
160378
|
-
email: email3,
|
|
160379
|
-
password
|
|
160380
|
-
});
|
|
160381
|
-
if (typeof authResult === "string") {
|
|
160382
|
-
const token = authResult;
|
|
160383
|
-
if (token) {
|
|
160384
|
-
await client.client.setToken(token);
|
|
160385
|
-
}
|
|
160386
|
-
}
|
|
160387
|
-
const customerResponse = await client.store.customer.retrieve();
|
|
160388
|
-
if (customerResponse.customer) {
|
|
160389
|
-
const identity = {
|
|
160390
|
-
id: {
|
|
160391
|
-
userId: customerResponse.customer.id
|
|
160392
|
-
},
|
|
160393
|
-
type: "Registered"
|
|
160394
|
-
};
|
|
160395
|
-
return identity;
|
|
160396
|
-
}
|
|
160397
|
-
return {
|
|
160398
|
-
type: "Anonymous"
|
|
160399
|
-
};
|
|
160400
|
-
} catch (error6) {
|
|
160401
|
-
debug29("Login failed:", error6);
|
|
160402
|
-
throw new Error(
|
|
160403
|
-
`Login failed: ${error6 instanceof Error ? error6.message : "Unknown error"}`
|
|
160404
|
-
);
|
|
160405
|
-
}
|
|
160406
|
-
}
|
|
160407
|
-
async logout(reqCtx) {
|
|
160408
|
-
const identity = {
|
|
160409
|
-
type: "Anonymous"
|
|
160410
|
-
};
|
|
160411
|
-
const client = await this.getClient();
|
|
160412
|
-
try {
|
|
160413
|
-
await client.auth.logout();
|
|
160414
|
-
await client.client.clearToken();
|
|
160415
|
-
return identity;
|
|
160416
|
-
} catch (error6) {
|
|
160417
|
-
debug29("Logout failed:", error6);
|
|
160418
|
-
await client.client.clearToken();
|
|
160419
|
-
return identity;
|
|
160420
|
-
}
|
|
160421
|
-
}
|
|
160422
|
-
async createAuthenticatedClient(reqCtx) {
|
|
160423
|
-
const tokenStore = new RequestContextTokenStore2(reqCtx);
|
|
160424
|
-
const authenticatedClient = new Medusa({
|
|
160425
|
-
baseUrl: this.config.apiUrl,
|
|
160426
|
-
publishableKey: this.config.publishable_key,
|
|
160427
|
-
debug: debug29.enabled,
|
|
160428
|
-
globalHeaders: {
|
|
160429
|
-
"x-medusa-locale": this.context.languageContext.locale
|
|
160430
|
-
},
|
|
160431
|
-
auth: {
|
|
160432
|
-
type: "jwt",
|
|
160433
|
-
jwtTokenStorageMethod: "custom",
|
|
160434
|
-
storage: tokenStore
|
|
160435
|
-
}
|
|
160436
|
-
});
|
|
160437
|
-
return authenticatedClient;
|
|
160438
|
-
}
|
|
160439
|
-
};
|
|
160440
|
-
}
|
|
160441
|
-
});
|
|
160442
|
-
|
|
160443
160585
|
// packages/medusa/src/capabilities/inventory.capability.ts
|
|
160444
160586
|
var import_debug30, debug30, MedusaInventoryCapability;
|
|
160445
160587
|
var init_inventory_capability5 = __esm({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/feeds",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.52",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
"url": "git+https://github.com/Solteq/reactionary.git"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@reactionary/algolia": "0.10.
|
|
16
|
-
"@reactionary/commercetools": "0.10.
|
|
17
|
-
"@reactionary/core": "0.10.
|
|
18
|
-
"@reactionary/fake": "0.10.
|
|
19
|
-
"@reactionary/magento": "0.10.
|
|
20
|
-
"@reactionary/medusa": "0.10.
|
|
21
|
-
"@reactionary/meilisearch": "0.10.
|
|
22
|
-
"@reactionary/unomi": "0.10.
|
|
15
|
+
"@reactionary/algolia": "0.10.52",
|
|
16
|
+
"@reactionary/commercetools": "0.10.52",
|
|
17
|
+
"@reactionary/core": "0.10.52",
|
|
18
|
+
"@reactionary/fake": "0.10.52",
|
|
19
|
+
"@reactionary/magento": "0.10.52",
|
|
20
|
+
"@reactionary/medusa": "0.10.52",
|
|
21
|
+
"@reactionary/meilisearch": "0.10.52",
|
|
22
|
+
"@reactionary/unomi": "0.10.52",
|
|
23
23
|
"commander": "^15.0.0",
|
|
24
24
|
"dotenv": "^17.2.2",
|
|
25
25
|
"sitemap": "^9.0.1",
|