@reactionary/feeds 0.10.51 → 0.10.53
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 +471 -321
- package/package.json +9 -9
package/cli.cjs
CHANGED
|
@@ -37347,6 +37347,8 @@ var init_profile_model = __esm({
|
|
|
37347
37347
|
ProfileSchema = BaseModelSchema.extend({
|
|
37348
37348
|
identifier: IdentityIdentifierSchema,
|
|
37349
37349
|
email: email2(),
|
|
37350
|
+
firstName: string2().optional(),
|
|
37351
|
+
lastName: string2().optional(),
|
|
37350
37352
|
phone: string2(),
|
|
37351
37353
|
emailVerified: boolean2(),
|
|
37352
37354
|
phoneVerified: boolean2(),
|
|
@@ -38136,7 +38138,9 @@ var init_profile_mutation = __esm({
|
|
|
38136
38138
|
ProfileMutationUpdateSchema = BaseMutationSchema.extend({
|
|
38137
38139
|
identifier: IdentityIdentifierSchema,
|
|
38138
38140
|
email: email2().meta({ description: "The main contact email of the profile" }),
|
|
38139
|
-
phone: string2().meta({ description: "The main phone number of the profile" })
|
|
38141
|
+
phone: string2().meta({ description: "The main phone number of the profile" }),
|
|
38142
|
+
firstName: string2().optional().meta({ description: "The first name of the profile holder. Left unchanged when omitted" }),
|
|
38143
|
+
lastName: string2().optional().meta({ description: "The last name of the profile holder. Left unchanged when omitted" })
|
|
38140
38144
|
});
|
|
38141
38145
|
ProfileMutationAddShippingAddressSchema = BaseMutationSchema.extend({
|
|
38142
38146
|
identifier: IdentityIdentifierSchema,
|
|
@@ -124896,6 +124900,8 @@ var init_profile_capability4 = __esm({
|
|
|
124896
124900
|
const updated = await this.magentoApi.updateMe({
|
|
124897
124901
|
...customer,
|
|
124898
124902
|
email: payload.email ?? customer.email,
|
|
124903
|
+
firstname: payload.firstName ?? customer.firstname,
|
|
124904
|
+
lastname: payload.lastName ?? customer.lastname,
|
|
124899
124905
|
custom_attributes: customAttributes
|
|
124900
124906
|
});
|
|
124901
124907
|
return success(this.factory.parseProfile(this.context, updated));
|
|
@@ -127641,6 +127647,8 @@ var init_profile_factory4 = __esm({
|
|
|
127641
127647
|
userId: String(customer.id)
|
|
127642
127648
|
},
|
|
127643
127649
|
email: customer.email,
|
|
127650
|
+
firstName: customer.firstname,
|
|
127651
|
+
lastName: customer.lastname,
|
|
127644
127652
|
emailVerified: true,
|
|
127645
127653
|
phone,
|
|
127646
127654
|
phoneVerified: false,
|
|
@@ -128372,7 +128380,7 @@ var init_configuration_schema5 = __esm({
|
|
|
128372
128380
|
});
|
|
128373
128381
|
|
|
128374
128382
|
// packages/medusa/src/schema/medusa.schema.ts
|
|
128375
|
-
var MedusaCartIdentifierSchema, MedusaOrderIdentifierSchema, MedusaRegionSchema, MedusaSessionSchema;
|
|
128383
|
+
var MedusaCartIdentifierSchema, MedusaOrderIdentifierSchema, MedusaRegionSchema, MedusaCachedPluginListSchema, MedusaSessionSchema;
|
|
128376
128384
|
var init_medusa_schema = __esm({
|
|
128377
128385
|
"packages/medusa/src/schema/medusa.schema.ts"() {
|
|
128378
128386
|
"use strict";
|
|
@@ -128389,6 +128397,9 @@ var init_medusa_schema = __esm({
|
|
|
128389
128397
|
name: string2(),
|
|
128390
128398
|
currency_code: string2()
|
|
128391
128399
|
});
|
|
128400
|
+
MedusaCachedPluginListSchema = looseObject({
|
|
128401
|
+
plugins: array(string2())
|
|
128402
|
+
});
|
|
128392
128403
|
MedusaSessionSchema = looseObject({
|
|
128393
128404
|
activeCartId: MedusaCartIdentifierSchema.optional(),
|
|
128394
128405
|
allOwnedCarts: record(string2(), array(MedusaCartIdentifierSchema)).optional(),
|
|
@@ -158017,6 +158028,235 @@ var require_dist3 = __commonJS({
|
|
|
158017
158028
|
}
|
|
158018
158029
|
});
|
|
158019
158030
|
|
|
158031
|
+
// packages/medusa/src/core/client.ts
|
|
158032
|
+
var import_debug21, debug21, SESSION_KEY2, RequestContextTokenStore2, Medusa, MedusaAdminAPI, MedusaAPI;
|
|
158033
|
+
var init_client6 = __esm({
|
|
158034
|
+
"packages/medusa/src/core/client.ts"() {
|
|
158035
|
+
"use strict";
|
|
158036
|
+
init_esm2();
|
|
158037
|
+
import_debug21 = __toESM(require_src(), 1);
|
|
158038
|
+
init_src6();
|
|
158039
|
+
debug21 = (0, import_debug21.default)("reactionary:medusa:client");
|
|
158040
|
+
SESSION_KEY2 = "MEDUSA_PROVIDER";
|
|
158041
|
+
RequestContextTokenStore2 = class {
|
|
158042
|
+
constructor(context2, keyPrefix = "__x") {
|
|
158043
|
+
this.context = context2;
|
|
158044
|
+
this.keyPrefix = keyPrefix;
|
|
158045
|
+
}
|
|
158046
|
+
context;
|
|
158047
|
+
keyPrefix;
|
|
158048
|
+
getItem(key) {
|
|
158049
|
+
if (this.context.session[SESSION_KEY2] === void 0) {
|
|
158050
|
+
this.context.session[SESSION_KEY2] = {};
|
|
158051
|
+
}
|
|
158052
|
+
const retVal = this.context.session[SESSION_KEY2] ? this.context.session[SESSION_KEY2][this.keyPrefix + "_" + key] || null : null;
|
|
158053
|
+
if (debug21.enabled) {
|
|
158054
|
+
debug21(
|
|
158055
|
+
`Getting token item for key: ${this.keyPrefix + "_" + key} - Found: ${retVal ? "Yes" : "No"}`
|
|
158056
|
+
);
|
|
158057
|
+
}
|
|
158058
|
+
return Promise.resolve(retVal);
|
|
158059
|
+
}
|
|
158060
|
+
setItem(key, value) {
|
|
158061
|
+
if (this.context.session[SESSION_KEY2] === void 0) {
|
|
158062
|
+
this.context.session[SESSION_KEY2] = {};
|
|
158063
|
+
}
|
|
158064
|
+
if (debug21.enabled) {
|
|
158065
|
+
debug21(
|
|
158066
|
+
`Setting token item for key: ${this.keyPrefix + "_" + key} - Value: <redacted, ${value.length} chars>`
|
|
158067
|
+
);
|
|
158068
|
+
}
|
|
158069
|
+
this.context.session[SESSION_KEY2][this.keyPrefix + "_" + key] = value;
|
|
158070
|
+
return Promise.resolve();
|
|
158071
|
+
}
|
|
158072
|
+
removeItem(key) {
|
|
158073
|
+
if (this.context.session[SESSION_KEY2] === void 0) {
|
|
158074
|
+
this.context.session[SESSION_KEY2] = {};
|
|
158075
|
+
}
|
|
158076
|
+
if (debug21.enabled) {
|
|
158077
|
+
debug21(`Removing token item for key: ${this.keyPrefix + "_" + key}`);
|
|
158078
|
+
}
|
|
158079
|
+
delete this.context.session[SESSION_KEY2][this.keyPrefix + "_" + key];
|
|
158080
|
+
return Promise.resolve();
|
|
158081
|
+
}
|
|
158082
|
+
};
|
|
158083
|
+
Medusa = class {
|
|
158084
|
+
client;
|
|
158085
|
+
admin;
|
|
158086
|
+
store;
|
|
158087
|
+
auth;
|
|
158088
|
+
constructor(config3) {
|
|
158089
|
+
this.client = new Client(config3);
|
|
158090
|
+
this.admin = new Admin(this.client);
|
|
158091
|
+
this.store = new Store2(this.client);
|
|
158092
|
+
this.auth = new Auth(this.client, config3);
|
|
158093
|
+
}
|
|
158094
|
+
};
|
|
158095
|
+
MedusaAdminAPI = class {
|
|
158096
|
+
config;
|
|
158097
|
+
client;
|
|
158098
|
+
context;
|
|
158099
|
+
constructor(config3, context2) {
|
|
158100
|
+
this.config = config3;
|
|
158101
|
+
this.context = context2;
|
|
158102
|
+
this.client = new Medusa({
|
|
158103
|
+
baseUrl: this.config.apiUrl,
|
|
158104
|
+
apiKey: this.config.adminApiKey,
|
|
158105
|
+
debug: debug21.enabled,
|
|
158106
|
+
globalHeaders: {
|
|
158107
|
+
"x-medusa-locale": this.context.languageContext.locale
|
|
158108
|
+
}
|
|
158109
|
+
});
|
|
158110
|
+
}
|
|
158111
|
+
async getClient() {
|
|
158112
|
+
return this.client;
|
|
158113
|
+
}
|
|
158114
|
+
};
|
|
158115
|
+
MedusaAPI = class {
|
|
158116
|
+
config;
|
|
158117
|
+
client;
|
|
158118
|
+
context;
|
|
158119
|
+
constructor(config3, context2) {
|
|
158120
|
+
this.config = config3;
|
|
158121
|
+
this.context = context2;
|
|
158122
|
+
this.client = void 0;
|
|
158123
|
+
}
|
|
158124
|
+
async getActiveRegion() {
|
|
158125
|
+
const session = this.getSessionData();
|
|
158126
|
+
if (session.selectedRegion) {
|
|
158127
|
+
if (session.selectedRegion.currency_code === this.context.languageContext.currencyCode.toLowerCase()) {
|
|
158128
|
+
return session.selectedRegion;
|
|
158129
|
+
}
|
|
158130
|
+
}
|
|
158131
|
+
const regions = await (await this.getClient()).store.region.list();
|
|
158132
|
+
const allRegions = [];
|
|
158133
|
+
for (const region of regions.regions) {
|
|
158134
|
+
allRegions.push({
|
|
158135
|
+
id: region.id,
|
|
158136
|
+
name: region.name,
|
|
158137
|
+
currency_code: region.currency_code
|
|
158138
|
+
});
|
|
158139
|
+
}
|
|
158140
|
+
const selectedRegion = allRegions.find(
|
|
158141
|
+
(r3) => r3.currency_code === this.context.languageContext.currencyCode.toLowerCase()
|
|
158142
|
+
) || allRegions[0];
|
|
158143
|
+
this.context.languageContext.currencyCode = (selectedRegion || allRegions[0]).currency_code.toUpperCase();
|
|
158144
|
+
this.setSessionData({
|
|
158145
|
+
allRegions,
|
|
158146
|
+
selectedRegion
|
|
158147
|
+
});
|
|
158148
|
+
return selectedRegion;
|
|
158149
|
+
}
|
|
158150
|
+
async getClient() {
|
|
158151
|
+
if (!this.client) {
|
|
158152
|
+
this.client = this.createAuthenticatedClient(this.context);
|
|
158153
|
+
}
|
|
158154
|
+
return await this.client;
|
|
158155
|
+
}
|
|
158156
|
+
getSessionData() {
|
|
158157
|
+
return this.context.session[SESSION_KEY2] ? this.context.session[SESSION_KEY2] : MedusaSessionSchema.parse({});
|
|
158158
|
+
}
|
|
158159
|
+
setSessionData(sessionData) {
|
|
158160
|
+
const existingData = this.context.session[SESSION_KEY2];
|
|
158161
|
+
this.context.session[SESSION_KEY2] = {
|
|
158162
|
+
...existingData,
|
|
158163
|
+
...sessionData
|
|
158164
|
+
};
|
|
158165
|
+
}
|
|
158166
|
+
async register(email3, password, firstName, lastName, reqCtx) {
|
|
158167
|
+
try {
|
|
158168
|
+
const client = await this.getClient();
|
|
158169
|
+
const tokenResponse = await client.auth.register(
|
|
158170
|
+
"customer",
|
|
158171
|
+
"emailpass",
|
|
158172
|
+
{
|
|
158173
|
+
email: email3,
|
|
158174
|
+
password
|
|
158175
|
+
}
|
|
158176
|
+
);
|
|
158177
|
+
const customer = await client.store.customer.create({
|
|
158178
|
+
email: email3,
|
|
158179
|
+
first_name: firstName,
|
|
158180
|
+
last_name: lastName
|
|
158181
|
+
});
|
|
158182
|
+
const identity = await this.login(email3, password, reqCtx);
|
|
158183
|
+
return identity;
|
|
158184
|
+
} catch (error6) {
|
|
158185
|
+
debug21("Registration failed:", error6);
|
|
158186
|
+
throw new Error(
|
|
158187
|
+
`Registration failed: ${error6 instanceof Error ? error6.message : "Unknown error"}`
|
|
158188
|
+
);
|
|
158189
|
+
}
|
|
158190
|
+
}
|
|
158191
|
+
async login(email3, password, reqCtx) {
|
|
158192
|
+
try {
|
|
158193
|
+
const client = await this.getClient();
|
|
158194
|
+
const authResult = await client.auth.login("customer", "emailpass", {
|
|
158195
|
+
email: email3,
|
|
158196
|
+
password
|
|
158197
|
+
});
|
|
158198
|
+
if (typeof authResult === "string") {
|
|
158199
|
+
const token = authResult;
|
|
158200
|
+
if (token) {
|
|
158201
|
+
await client.client.setToken(token);
|
|
158202
|
+
}
|
|
158203
|
+
}
|
|
158204
|
+
const customerResponse = await client.store.customer.retrieve();
|
|
158205
|
+
if (customerResponse.customer) {
|
|
158206
|
+
const identity = {
|
|
158207
|
+
id: {
|
|
158208
|
+
userId: customerResponse.customer.id
|
|
158209
|
+
},
|
|
158210
|
+
type: "Registered"
|
|
158211
|
+
};
|
|
158212
|
+
return identity;
|
|
158213
|
+
}
|
|
158214
|
+
return {
|
|
158215
|
+
type: "Anonymous"
|
|
158216
|
+
};
|
|
158217
|
+
} catch (error6) {
|
|
158218
|
+
debug21("Login failed:", error6);
|
|
158219
|
+
throw new Error(
|
|
158220
|
+
`Login failed: ${error6 instanceof Error ? error6.message : "Unknown error"}`
|
|
158221
|
+
);
|
|
158222
|
+
}
|
|
158223
|
+
}
|
|
158224
|
+
async logout(reqCtx) {
|
|
158225
|
+
const identity = {
|
|
158226
|
+
type: "Anonymous"
|
|
158227
|
+
};
|
|
158228
|
+
const client = await this.getClient();
|
|
158229
|
+
try {
|
|
158230
|
+
await client.auth.logout();
|
|
158231
|
+
await client.client.clearToken();
|
|
158232
|
+
return identity;
|
|
158233
|
+
} catch (error6) {
|
|
158234
|
+
debug21("Logout failed:", error6);
|
|
158235
|
+
await client.client.clearToken();
|
|
158236
|
+
return identity;
|
|
158237
|
+
}
|
|
158238
|
+
}
|
|
158239
|
+
async createAuthenticatedClient(reqCtx) {
|
|
158240
|
+
const tokenStore = new RequestContextTokenStore2(reqCtx);
|
|
158241
|
+
const authenticatedClient = new Medusa({
|
|
158242
|
+
baseUrl: this.config.apiUrl,
|
|
158243
|
+
publishableKey: this.config.publishable_key,
|
|
158244
|
+
debug: debug21.enabled,
|
|
158245
|
+
globalHeaders: {
|
|
158246
|
+
"x-medusa-locale": this.context.languageContext.locale
|
|
158247
|
+
},
|
|
158248
|
+
auth: {
|
|
158249
|
+
type: "jwt",
|
|
158250
|
+
jwtTokenStorageMethod: "custom",
|
|
158251
|
+
storage: tokenStore
|
|
158252
|
+
}
|
|
158253
|
+
});
|
|
158254
|
+
return authenticatedClient;
|
|
158255
|
+
}
|
|
158256
|
+
};
|
|
158257
|
+
}
|
|
158258
|
+
});
|
|
158259
|
+
|
|
158020
158260
|
// packages/medusa/src/utils/medusa-helpers.ts
|
|
158021
158261
|
function isNotFoundFetchError(error6) {
|
|
158022
158262
|
return error6 instanceof FetchError && error6.status === 404;
|
|
@@ -158079,8 +158319,8 @@ function parseMedusaItemPrice(remoteItem, currency) {
|
|
|
158079
158319
|
};
|
|
158080
158320
|
}
|
|
158081
158321
|
function handleProviderError(action, error6) {
|
|
158082
|
-
if (
|
|
158083
|
-
|
|
158322
|
+
if (debug22.enabled) {
|
|
158323
|
+
debug22(`Failed to ${action}:`, error6);
|
|
158084
158324
|
}
|
|
158085
158325
|
throw new Error(
|
|
158086
158326
|
`Failed to ${action}: ${error6 instanceof Error ? error6.message : "Unknown error"}`
|
|
@@ -158098,27 +158338,29 @@ function safeStringConvert(val, defaultValue) {
|
|
|
158098
158338
|
}
|
|
158099
158339
|
return String(val);
|
|
158100
158340
|
}
|
|
158101
|
-
var
|
|
158341
|
+
var import_debug22, debug22;
|
|
158102
158342
|
var init_medusa_helpers = __esm({
|
|
158103
158343
|
"packages/medusa/src/utils/medusa-helpers.ts"() {
|
|
158104
158344
|
"use strict";
|
|
158105
158345
|
init_esm2();
|
|
158106
|
-
|
|
158107
|
-
|
|
158346
|
+
import_debug22 = __toESM(require_src(), 1);
|
|
158347
|
+
debug22 = (0, import_debug22.default)("reactionary:medusa:helpers");
|
|
158108
158348
|
}
|
|
158109
158349
|
});
|
|
158110
158350
|
|
|
158111
158351
|
// packages/medusa/src/capabilities/cart.capability.ts
|
|
158112
|
-
var import_types11,
|
|
158352
|
+
var import_types11, import_debug23, debug23, MedusaCartCapability;
|
|
158113
158353
|
var init_cart_capability5 = __esm({
|
|
158114
158354
|
"packages/medusa/src/capabilities/cart.capability.ts"() {
|
|
158115
158355
|
"use strict";
|
|
158116
158356
|
init_src();
|
|
158117
158357
|
init_esm2();
|
|
158118
158358
|
import_types11 = __toESM(require_dist3(), 1);
|
|
158119
|
-
|
|
158359
|
+
import_debug23 = __toESM(require_src(), 1);
|
|
158360
|
+
init_client6();
|
|
158361
|
+
init_medusa_schema();
|
|
158120
158362
|
init_medusa_helpers();
|
|
158121
|
-
|
|
158363
|
+
debug23 = (0, import_debug23.default)("reactionary:medusa:cart");
|
|
158122
158364
|
MedusaCartCapability = class extends CartCapability {
|
|
158123
158365
|
constructor(config3, cache, context2, medusaApi, factory) {
|
|
158124
158366
|
super(cache, context2);
|
|
@@ -158136,7 +158378,87 @@ var init_cart_capability5 = __esm({
|
|
|
158136
158378
|
* example: this.includedFields = [includedFields, '+discounts.*'].join(',');
|
|
158137
158379
|
*/
|
|
158138
158380
|
includedFields = ["+items.*", "+items.adjustments.*", "+shipping_methods.adjustments.*"].join(",");
|
|
158381
|
+
/**
|
|
158382
|
+
* Fields requested when listing owned carts, both via the cart-ownership
|
|
158383
|
+
* endpoint and via the session-tracked fallback. Every entry must be in
|
|
158384
|
+
* the allowed field set of both routes; `customer.id` stands in for
|
|
158385
|
+
* `customer_id`, which is not an allowed field (see normalizeOwnedCart).
|
|
158386
|
+
*/
|
|
158387
|
+
ownedCartListFields = ["id", "updated_at", "metadata", "items.id", "customer.id"].join(",");
|
|
158388
|
+
/** Sort order for the server-side owned-carts listing. */
|
|
158389
|
+
ownedCartListOrder = "-updated_at";
|
|
158390
|
+
/**
|
|
158391
|
+
* Package name of the optional backend plugin that serves
|
|
158392
|
+
* `GET /store/customers/me/carts` (a logged-in customer's open carts).
|
|
158393
|
+
*/
|
|
158394
|
+
cartOwnershipPluginName = "@solteq-excom/medusa-cart-ownership";
|
|
158395
|
+
/**
|
|
158396
|
+
* How long a backend's plugin list stays cached. Bounds how late a newly
|
|
158397
|
+
* (un)installed cart-ownership plugin is noticed.
|
|
158398
|
+
*/
|
|
158399
|
+
pluginDetectionTtlSeconds = 900;
|
|
158139
158400
|
async listCarts(payload) {
|
|
158401
|
+
let data = null;
|
|
158402
|
+
if (await this.shouldUseOwnershipEndpoint(payload)) {
|
|
158403
|
+
data = await this.listCartsViaOwnershipEndpoint(payload);
|
|
158404
|
+
}
|
|
158405
|
+
data ??= await this.listCartsFromSession(payload);
|
|
158406
|
+
return success(this.factory.parseCartPaginatedSearchResult(this.context, data, payload));
|
|
158407
|
+
}
|
|
158408
|
+
/**
|
|
158409
|
+
* The server-side owned-carts listing only applies to a logged-in
|
|
158410
|
+
* customer's own carts: a company bucket and anonymous/guest carts are
|
|
158411
|
+
* only known to the session, and the backend only serves the route when
|
|
158412
|
+
* the cart-ownership plugin is installed.
|
|
158413
|
+
*/
|
|
158414
|
+
async shouldUseOwnershipEndpoint(payload) {
|
|
158415
|
+
if (payload.search.company) {
|
|
158416
|
+
return false;
|
|
158417
|
+
}
|
|
158418
|
+
if (this.context.session.identityContext.identity.type !== "Registered") {
|
|
158419
|
+
return false;
|
|
158420
|
+
}
|
|
158421
|
+
return await this.isCartOwnershipPluginEnabled();
|
|
158422
|
+
}
|
|
158423
|
+
/**
|
|
158424
|
+
* Lists the customer's open carts through the cart-ownership plugin's
|
|
158425
|
+
* `GET /store/customers/me/carts`. Returns null when the backend turns
|
|
158426
|
+
* out not to serve the route after all (404: plugin configured but not
|
|
158427
|
+
* built; 401: the token is no longer valid), so the caller falls back to
|
|
158428
|
+
* the session-tracked list. Other errors are real backend faults and
|
|
158429
|
+
* propagate.
|
|
158430
|
+
*/
|
|
158431
|
+
async listCartsViaOwnershipEndpoint(payload) {
|
|
158432
|
+
const client = await this.getClient();
|
|
158433
|
+
const { pageNumber, pageSize } = payload.search.paginationOptions;
|
|
158434
|
+
try {
|
|
158435
|
+
const response = await client.client.fetch("/store/customers/me/carts", {
|
|
158436
|
+
method: "GET",
|
|
158437
|
+
query: {
|
|
158438
|
+
fields: this.ownedCartListFields,
|
|
158439
|
+
limit: pageSize,
|
|
158440
|
+
offset: (pageNumber - 1) * pageSize,
|
|
158441
|
+
order: this.ownedCartListOrder
|
|
158442
|
+
}
|
|
158443
|
+
});
|
|
158444
|
+
return {
|
|
158445
|
+
items: response.carts.map((cart) => this.normalizeOwnedCart(cart)),
|
|
158446
|
+
totalCount: response.count
|
|
158447
|
+
};
|
|
158448
|
+
} catch (err) {
|
|
158449
|
+
if (this.shouldFallBackToSessionList(err)) {
|
|
158450
|
+
debug23("Owned-carts endpoint unavailable, falling back to session-tracked carts:", err);
|
|
158451
|
+
return null;
|
|
158452
|
+
}
|
|
158453
|
+
throw err;
|
|
158454
|
+
}
|
|
158455
|
+
}
|
|
158456
|
+
/**
|
|
158457
|
+
* Lists carts from the ids tracked in the session: the behavior from
|
|
158458
|
+
* before the cart-ownership plugin existed, and still the only source for
|
|
158459
|
+
* anonymous/guest carts and company buckets.
|
|
158460
|
+
*/
|
|
158461
|
+
async listCartsFromSession(payload) {
|
|
158140
158462
|
const client = await this.getClient();
|
|
158141
158463
|
const sessionData = this.medusaApi.getSessionData();
|
|
158142
158464
|
let cartCollection = payload.search.company ? sessionData.allOwnedCarts?.[payload.search.company.taxIdentifier] : sessionData.allOwnedCarts?.["_me"];
|
|
@@ -158146,29 +158468,69 @@ var init_cart_capability5 = __esm({
|
|
|
158146
158468
|
} else {
|
|
158147
158469
|
cartCollection = [];
|
|
158148
158470
|
}
|
|
158149
|
-
const
|
|
158150
|
-
const allPromises = cartCollection.map((cartIdentifier) => client.store.cart.retrieve(cartIdentifier.key, { fields: shortFields }));
|
|
158471
|
+
const allPromises = cartCollection.map((cartIdentifier) => client.store.cart.retrieve(cartIdentifier.key, { fields: this.ownedCartListFields }));
|
|
158151
158472
|
const responses = await Promise.all(allPromises);
|
|
158152
158473
|
const carts = responses.map((response) => response.cart).filter((cart) => !!cart);
|
|
158153
|
-
return
|
|
158154
|
-
this.
|
|
158155
|
-
|
|
158156
|
-
|
|
158157
|
-
|
|
158158
|
-
|
|
158159
|
-
|
|
158160
|
-
|
|
158474
|
+
return {
|
|
158475
|
+
items: carts.map((cart) => this.normalizeOwnedCart(cart)),
|
|
158476
|
+
totalCount
|
|
158477
|
+
};
|
|
158478
|
+
}
|
|
158479
|
+
/**
|
|
158480
|
+
* The factory reads `customer_id`, but only the `customer.id` relation is
|
|
158481
|
+
* an allowed list field, so copy it over when `customer_id` itself wasn't
|
|
158482
|
+
* returned.
|
|
158483
|
+
*/
|
|
158484
|
+
normalizeOwnedCart(cart) {
|
|
158485
|
+
return { ...cart, customer_id: cart.customer_id ?? cart.customer?.id };
|
|
158486
|
+
}
|
|
158487
|
+
/** A 404 (route not served) or 401 (token no longer valid) degrades to the session list. */
|
|
158488
|
+
shouldFallBackToSessionList(err) {
|
|
158489
|
+
return err instanceof FetchError && (err.status === 404 || err.status === 401);
|
|
158490
|
+
}
|
|
158491
|
+
/**
|
|
158492
|
+
* Checks whether the backend has the cart-ownership plugin, by its name in
|
|
158493
|
+
* core's `GET /admin/plugins`. Detection must never break cart listing, so
|
|
158494
|
+
* any failure just reports the plugin as absent.
|
|
158495
|
+
*/
|
|
158496
|
+
async isCartOwnershipPluginEnabled() {
|
|
158497
|
+
const plugins = await this.fetchEnabledPlugins();
|
|
158498
|
+
return plugins.includes(this.cartOwnershipPluginName);
|
|
158499
|
+
}
|
|
158500
|
+
/**
|
|
158501
|
+
* The backend's configured plugin list, kept in the reactionary cache
|
|
158502
|
+
* (shared across sessions) so not every request re-asks the admin API.
|
|
158503
|
+
* Failures are not cached: a plugin-less answer from here only costs the
|
|
158504
|
+
* fallback behavior, while caching a transient failure would hide the
|
|
158505
|
+
* plugin for a whole TTL.
|
|
158506
|
+
*/
|
|
158507
|
+
async fetchEnabledPlugins() {
|
|
158508
|
+
const cacheKey = `medusa:plugins:${this.config.apiUrl}`;
|
|
158509
|
+
const cached2 = await this.cache.get(cacheKey, MedusaCachedPluginListSchema);
|
|
158510
|
+
if (cached2) {
|
|
158511
|
+
return cached2.plugins;
|
|
158512
|
+
}
|
|
158513
|
+
try {
|
|
158514
|
+
const adminClient = await new MedusaAdminAPI(this.config, this.context).getClient();
|
|
158515
|
+
const response = await adminClient.client.fetch("/admin/plugins", { method: "GET" });
|
|
158516
|
+
const plugins = response.plugins.map((plugin) => plugin.name);
|
|
158517
|
+
await this.cache.put(cacheKey, { plugins }, { ttlSeconds: this.pluginDetectionTtlSeconds, dependencyIds: [] });
|
|
158518
|
+
return plugins;
|
|
158519
|
+
} catch (err) {
|
|
158520
|
+
debug23("Failed to list backend plugins:", err);
|
|
158521
|
+
return [];
|
|
158522
|
+
}
|
|
158161
158523
|
}
|
|
158162
158524
|
async getById(payload) {
|
|
158163
158525
|
try {
|
|
158164
158526
|
const client = await this.getClient();
|
|
158165
158527
|
const medusaId = payload.cart;
|
|
158166
|
-
if (
|
|
158167
|
-
|
|
158528
|
+
if (debug23.enabled) {
|
|
158529
|
+
debug23("Fetching cart by ID:", medusaId.key);
|
|
158168
158530
|
}
|
|
158169
158531
|
const cartResponse = await client.store.cart.retrieve(medusaId.key, { fields: this.includedFields });
|
|
158170
|
-
if (
|
|
158171
|
-
|
|
158532
|
+
if (debug23.enabled) {
|
|
158533
|
+
debug23("Received cart response:", cartResponse);
|
|
158172
158534
|
}
|
|
158173
158535
|
if (cartResponse.cart) {
|
|
158174
158536
|
return success(this.factory.parseCart(this.context, cartResponse.cart));
|
|
@@ -158178,7 +158540,7 @@ var init_cart_capability5 = __esm({
|
|
|
158178
158540
|
identifier: payload
|
|
158179
158541
|
});
|
|
158180
158542
|
} catch (err) {
|
|
158181
|
-
|
|
158543
|
+
debug23("Failed to get cart by ID:", err);
|
|
158182
158544
|
return error2({
|
|
158183
158545
|
type: "NotFound",
|
|
158184
158546
|
identifier: payload
|
|
@@ -158209,8 +158571,8 @@ var init_cart_capability5 = __esm({
|
|
|
158209
158571
|
});
|
|
158210
158572
|
}
|
|
158211
158573
|
const medusaId = cartIdentifier;
|
|
158212
|
-
if (
|
|
158213
|
-
|
|
158574
|
+
if (debug23.enabled) {
|
|
158575
|
+
debug23(
|
|
158214
158576
|
"Adding item to cart ID:",
|
|
158215
158577
|
medusaId.key,
|
|
158216
158578
|
"SKU:",
|
|
@@ -158247,8 +158609,8 @@ var init_cart_capability5 = __esm({
|
|
|
158247
158609
|
fields: this.includedFields
|
|
158248
158610
|
}
|
|
158249
158611
|
);
|
|
158250
|
-
if (
|
|
158251
|
-
|
|
158612
|
+
if (debug23.enabled) {
|
|
158613
|
+
debug23("Received add item response:", response);
|
|
158252
158614
|
}
|
|
158253
158615
|
if (response.cart) {
|
|
158254
158616
|
return success(this.factory.parseCart(this.context, response.cart));
|
|
@@ -158303,6 +158665,21 @@ var init_cart_capability5 = __esm({
|
|
|
158303
158665
|
}
|
|
158304
158666
|
};
|
|
158305
158667
|
}
|
|
158668
|
+
/**
|
|
158669
|
+
* Session tracking is skipped for a logged-in customer's own carts when
|
|
158670
|
+
* the backend has the cart-ownership plugin: the backend attributes the
|
|
158671
|
+
* cart to the customer at creation and lists it server-side. Anonymous
|
|
158672
|
+
* carts and company buckets are still only known to the session.
|
|
158673
|
+
*/
|
|
158674
|
+
async shouldTrackOwnedCartInSession(payload) {
|
|
158675
|
+
if (payload.company) {
|
|
158676
|
+
return true;
|
|
158677
|
+
}
|
|
158678
|
+
if (this.context.session.identityContext.identity.type !== "Registered") {
|
|
158679
|
+
return true;
|
|
158680
|
+
}
|
|
158681
|
+
return !await this.isCartOwnershipPluginEnabled();
|
|
158682
|
+
}
|
|
158306
158683
|
addCartToOwnedList(cartIdentifier, companyId) {
|
|
158307
158684
|
const sessionData = this.medusaApi.getSessionData();
|
|
158308
158685
|
const companyIdToUse = companyId ? companyId.taxIdentifier : "_me";
|
|
@@ -158362,7 +158739,9 @@ var init_cart_capability5 = __esm({
|
|
|
158362
158739
|
}
|
|
158363
158740
|
);
|
|
158364
158741
|
if (response.cart) {
|
|
158365
|
-
|
|
158742
|
+
if (await this.shouldTrackOwnedCartInSession(payload)) {
|
|
158743
|
+
this.addCartToOwnedList(this.factory.parseCartIdentifier(this.context, response.cart), payload.company);
|
|
158744
|
+
}
|
|
158366
158745
|
this.medusaApi.setSessionData({
|
|
158367
158746
|
activeCartId: this.factory.parseCartIdentifier(this.context, response.cart)
|
|
158368
158747
|
});
|
|
@@ -158461,7 +158840,7 @@ var init_cart_capability5 = __esm({
|
|
|
158461
158840
|
identifier: void 0
|
|
158462
158841
|
});
|
|
158463
158842
|
} catch (err) {
|
|
158464
|
-
|
|
158843
|
+
debug23("Failed to get active cart ID:", err);
|
|
158465
158844
|
return error2({
|
|
158466
158845
|
type: "NotFound",
|
|
158467
158846
|
identifier: void 0
|
|
@@ -158833,15 +159212,15 @@ var init_category_capability5 = __esm({
|
|
|
158833
159212
|
});
|
|
158834
159213
|
|
|
158835
159214
|
// packages/medusa/src/capabilities/checkout.capability.ts
|
|
158836
|
-
var
|
|
159215
|
+
var import_debug24, debug24, CheckoutNotReadyForFinalizationError3, MedusaCheckoutCapability;
|
|
158837
159216
|
var init_checkout_capability5 = __esm({
|
|
158838
159217
|
"packages/medusa/src/capabilities/checkout.capability.ts"() {
|
|
158839
159218
|
"use strict";
|
|
158840
159219
|
init_src();
|
|
158841
|
-
|
|
159220
|
+
import_debug24 = __toESM(require_src(), 1);
|
|
158842
159221
|
init_zod();
|
|
158843
159222
|
init_medusa_helpers();
|
|
158844
|
-
|
|
159223
|
+
debug24 = (0, import_debug24.default)("reactionary:medusa:checkout");
|
|
158845
159224
|
CheckoutNotReadyForFinalizationError3 = class extends Error {
|
|
158846
159225
|
constructor(checkoutIdentifier) {
|
|
158847
159226
|
super(
|
|
@@ -158881,8 +159260,8 @@ var init_checkout_capability5 = __esm({
|
|
|
158881
159260
|
}
|
|
158882
159261
|
async initiateCheckoutForCart(payload) {
|
|
158883
159262
|
const client = await this.medusaApi.getClient();
|
|
158884
|
-
if (
|
|
158885
|
-
|
|
159263
|
+
if (debug24.enabled) {
|
|
159264
|
+
debug24(
|
|
158886
159265
|
`Initiating checkout for cart with key: ${payload.cart.identifier.key}`
|
|
158887
159266
|
);
|
|
158888
159267
|
}
|
|
@@ -158951,8 +159330,8 @@ var init_checkout_capability5 = __esm({
|
|
|
158951
159330
|
}
|
|
158952
159331
|
async getAvailableShippingMethods(payload) {
|
|
158953
159332
|
const client = await this.medusaApi.getClient();
|
|
158954
|
-
if (
|
|
158955
|
-
|
|
159333
|
+
if (debug24.enabled) {
|
|
159334
|
+
debug24(
|
|
158956
159335
|
`Fetching available shipping methods for checkout with key: ${payload.checkout.key}`
|
|
158957
159336
|
);
|
|
158958
159337
|
}
|
|
@@ -158960,8 +159339,8 @@ var init_checkout_capability5 = __esm({
|
|
|
158960
159339
|
this.getAvailableShippingMethodsPayload(payload)
|
|
158961
159340
|
);
|
|
158962
159341
|
const shippingMethods = [];
|
|
158963
|
-
if (
|
|
158964
|
-
|
|
159342
|
+
if (debug24.enabled) {
|
|
159343
|
+
debug24(
|
|
158965
159344
|
`Found ${shippingMethodResponse.shipping_options.length} shipping methods for checkout with key: ${payload.checkout.key}`,
|
|
158966
159345
|
shippingMethodResponse.shipping_options
|
|
158967
159346
|
);
|
|
@@ -158973,13 +159352,13 @@ var init_checkout_capability5 = __esm({
|
|
|
158973
159352
|
sm.calculated_price = updatedSM.shipping_option.calculated_price;
|
|
158974
159353
|
});
|
|
158975
159354
|
if (calculatedPricesPromises.length > 0) {
|
|
158976
|
-
if (
|
|
158977
|
-
|
|
159355
|
+
if (debug24.enabled) {
|
|
159356
|
+
debug24("Calculating prices for {0} shipping methods for checkout with key: {1}", [calculatedPricesPromises.length, payload.checkout.key]);
|
|
158978
159357
|
}
|
|
158979
159358
|
await Promise.all(calculatedPricesPromises);
|
|
158980
|
-
if (
|
|
158981
|
-
|
|
158982
|
-
|
|
159359
|
+
if (debug24.enabled) {
|
|
159360
|
+
debug24("Finished calculating prices for {0} shipping methods for checkout with key: {1}", [calculatedPricesPromises.length, payload.checkout.key]);
|
|
159361
|
+
debug24(`Updated shipping methods for checkout with key: ${payload.checkout.key}`, shippingMethodResponse.shipping_options);
|
|
158983
159362
|
}
|
|
158984
159363
|
}
|
|
158985
159364
|
for (const sm of shippingMethodResponse.shipping_options) {
|
|
@@ -158989,8 +159368,8 @@ var init_checkout_capability5 = __esm({
|
|
|
158989
159368
|
}
|
|
158990
159369
|
shippingMethods.push(this.factory.parseShippingMethod(this.context, sm));
|
|
158991
159370
|
}
|
|
158992
|
-
if (
|
|
158993
|
-
|
|
159371
|
+
if (debug24.enabled) {
|
|
159372
|
+
debug24(
|
|
158994
159373
|
`Found ${shippingMethods.length} shipping methods for checkout with key: ${payload.checkout.key}`,
|
|
158995
159374
|
shippingMethods
|
|
158996
159375
|
);
|
|
@@ -159006,8 +159385,8 @@ var init_checkout_capability5 = __esm({
|
|
|
159006
159385
|
}
|
|
159007
159386
|
async getAvailablePaymentMethods(payload) {
|
|
159008
159387
|
const client = await this.medusaApi.getClient();
|
|
159009
|
-
if (
|
|
159010
|
-
|
|
159388
|
+
if (debug24.enabled) {
|
|
159389
|
+
debug24(
|
|
159011
159390
|
`Fetching available payment methods for checkout with key: ${payload.checkout.key}`
|
|
159012
159391
|
);
|
|
159013
159392
|
}
|
|
@@ -159023,8 +159402,8 @@ var init_checkout_capability5 = __esm({
|
|
|
159023
159402
|
const payMethod = this.factory.parsePaymentMethod(this.context, pm);
|
|
159024
159403
|
paymentMethods.push(payMethod);
|
|
159025
159404
|
}
|
|
159026
|
-
if (
|
|
159027
|
-
|
|
159405
|
+
if (debug24.enabled) {
|
|
159406
|
+
debug24(
|
|
159028
159407
|
`Found ${paymentMethods.length} payment methods for checkout with key: ${payload.checkout.key}`,
|
|
159029
159408
|
paymentMethods
|
|
159030
159409
|
);
|
|
@@ -159042,8 +159421,8 @@ var init_checkout_capability5 = __esm({
|
|
|
159042
159421
|
}
|
|
159043
159422
|
async addPaymentInstruction(payload) {
|
|
159044
159423
|
const client = await this.medusaApi.getClient();
|
|
159045
|
-
if (
|
|
159046
|
-
|
|
159424
|
+
if (debug24.enabled) {
|
|
159425
|
+
debug24(
|
|
159047
159426
|
`Adding payment instruction ${payload.paymentInstruction.paymentMethod.name} to checkout with key: ${payload.checkout.key}`
|
|
159048
159427
|
);
|
|
159049
159428
|
}
|
|
@@ -159060,7 +159439,7 @@ var init_checkout_capability5 = __esm({
|
|
|
159060
159439
|
);
|
|
159061
159440
|
return success(this.factory.parseCheckout(this.context, updatedCartResponse.cart));
|
|
159062
159441
|
} catch (error6) {
|
|
159063
|
-
|
|
159442
|
+
debug24("Failed to add payment instruction: {0}", [error6]);
|
|
159064
159443
|
throw new Error(
|
|
159065
159444
|
`Failed to add payment instruction: ${error6 instanceof Error ? error6.message : "Unknown error"}`
|
|
159066
159445
|
);
|
|
@@ -159216,15 +159595,15 @@ var init_checkout_capability5 = __esm({
|
|
|
159216
159595
|
});
|
|
159217
159596
|
|
|
159218
159597
|
// packages/medusa/src/capabilities/company.capability.ts
|
|
159219
|
-
var
|
|
159598
|
+
var import_debug25, debug25, MedusaCompanyCapability;
|
|
159220
159599
|
var init_company_capability3 = __esm({
|
|
159221
159600
|
"packages/medusa/src/capabilities/company.capability.ts"() {
|
|
159222
159601
|
"use strict";
|
|
159223
159602
|
init_esm2();
|
|
159224
159603
|
init_src();
|
|
159225
|
-
|
|
159604
|
+
import_debug25 = __toESM(require_src(), 1);
|
|
159226
159605
|
init_medusa_helpers();
|
|
159227
|
-
|
|
159606
|
+
debug25 = (0, import_debug25.default)("reactionary:medusa:company");
|
|
159228
159607
|
MedusaCompanyCapability = class extends CompanyCapability {
|
|
159229
159608
|
constructor(config3, cache, context2, medusaApi, factory) {
|
|
159230
159609
|
super(cache, context2);
|
|
@@ -159302,7 +159681,7 @@ var init_company_capability3 = __esm({
|
|
|
159302
159681
|
}
|
|
159303
159682
|
}
|
|
159304
159683
|
async listCompanies(payload) {
|
|
159305
|
-
|
|
159684
|
+
debug25("listCompanies", payload);
|
|
159306
159685
|
try {
|
|
159307
159686
|
const client = await this.medusaApi.getClient();
|
|
159308
159687
|
const response = await client.client.fetch("/store/customers/me/employees", { method: "GET" });
|
|
@@ -159325,7 +159704,7 @@ var init_company_capability3 = __esm({
|
|
|
159325
159704
|
}
|
|
159326
159705
|
}
|
|
159327
159706
|
async addShippingAddress(payload) {
|
|
159328
|
-
|
|
159707
|
+
debug25("addShippingAddress", payload);
|
|
159329
159708
|
try {
|
|
159330
159709
|
const company = await this.fetchCompanyByTaxIdentifier(payload.company.taxIdentifier);
|
|
159331
159710
|
if (!company) {
|
|
@@ -159350,7 +159729,7 @@ var init_company_capability3 = __esm({
|
|
|
159350
159729
|
}
|
|
159351
159730
|
}
|
|
159352
159731
|
async updateShippingAddress(payload) {
|
|
159353
|
-
|
|
159732
|
+
debug25("updateShippingAddress", payload);
|
|
159354
159733
|
try {
|
|
159355
159734
|
const company = await this.fetchCompanyByTaxIdentifier(payload.company.taxIdentifier);
|
|
159356
159735
|
if (!company) {
|
|
@@ -159372,7 +159751,7 @@ var init_company_capability3 = __esm({
|
|
|
159372
159751
|
}
|
|
159373
159752
|
}
|
|
159374
159753
|
async removeShippingAddress(payload) {
|
|
159375
|
-
|
|
159754
|
+
debug25("removeShippingAddress", payload);
|
|
159376
159755
|
try {
|
|
159377
159756
|
const company = await this.fetchCompanyByTaxIdentifier(payload.company.taxIdentifier);
|
|
159378
159757
|
if (!company) {
|
|
@@ -159393,7 +159772,7 @@ var init_company_capability3 = __esm({
|
|
|
159393
159772
|
}
|
|
159394
159773
|
}
|
|
159395
159774
|
async makeShippingAddressDefault(payload) {
|
|
159396
|
-
|
|
159775
|
+
debug25("makeShippingAddressDefault", payload);
|
|
159397
159776
|
try {
|
|
159398
159777
|
const company = await this.fetchCompanyByTaxIdentifier(payload.company.taxIdentifier);
|
|
159399
159778
|
if (!company) {
|
|
@@ -159455,15 +159834,15 @@ var init_company_capability3 = __esm({
|
|
|
159455
159834
|
});
|
|
159456
159835
|
|
|
159457
159836
|
// packages/medusa/src/capabilities/company-registration.capability.ts
|
|
159458
|
-
var
|
|
159837
|
+
var import_debug26, debug26, MedusaCompanyRegistrationCapability;
|
|
159459
159838
|
var init_company_registration_capability3 = __esm({
|
|
159460
159839
|
"packages/medusa/src/capabilities/company-registration.capability.ts"() {
|
|
159461
159840
|
"use strict";
|
|
159462
159841
|
init_esm2();
|
|
159463
159842
|
init_src();
|
|
159464
|
-
|
|
159843
|
+
import_debug26 = __toESM(require_src(), 1);
|
|
159465
159844
|
init_medusa_helpers();
|
|
159466
|
-
|
|
159845
|
+
debug26 = (0, import_debug26.default)("reactionary:medusa:company-registration");
|
|
159467
159846
|
MedusaCompanyRegistrationCapability = class extends CompanyRegistrationCapability {
|
|
159468
159847
|
constructor(config3, cache, context2, medusaApi, factory) {
|
|
159469
159848
|
super(cache, context2);
|
|
@@ -159503,7 +159882,7 @@ var init_company_registration_capability3 = __esm({
|
|
|
159503
159882
|
};
|
|
159504
159883
|
}
|
|
159505
159884
|
async requestRegistration(payload) {
|
|
159506
|
-
|
|
159885
|
+
debug26("requestRegistration", payload);
|
|
159507
159886
|
try {
|
|
159508
159887
|
const client = await this.medusaApi.getClient();
|
|
159509
159888
|
const createResponse = await client.client.fetch(
|
|
@@ -159530,7 +159909,7 @@ var init_company_registration_capability3 = __esm({
|
|
|
159530
159909
|
}
|
|
159531
159910
|
}
|
|
159532
159911
|
async checkRequestStatus(payload) {
|
|
159533
|
-
|
|
159912
|
+
debug26("checkRequestStatus", payload);
|
|
159534
159913
|
try {
|
|
159535
159914
|
const company = await this.fetchCompany(payload.requestIdentifier.key);
|
|
159536
159915
|
if (!company) {
|
|
@@ -159558,15 +159937,15 @@ var init_company_registration_capability3 = __esm({
|
|
|
159558
159937
|
});
|
|
159559
159938
|
|
|
159560
159939
|
// packages/medusa/src/capabilities/employee.capability.ts
|
|
159561
|
-
var
|
|
159940
|
+
var import_debug27, debug27, EMPLOYEE_FIELDS, MedusaEmployeeCapability;
|
|
159562
159941
|
var init_employee_capability3 = __esm({
|
|
159563
159942
|
"packages/medusa/src/capabilities/employee.capability.ts"() {
|
|
159564
159943
|
"use strict";
|
|
159565
159944
|
init_esm2();
|
|
159566
159945
|
init_src();
|
|
159567
|
-
|
|
159946
|
+
import_debug27 = __toESM(require_src(), 1);
|
|
159568
159947
|
init_medusa_helpers();
|
|
159569
|
-
|
|
159948
|
+
debug27 = (0, import_debug27.default)("reactionary:medusa:employee");
|
|
159570
159949
|
EMPLOYEE_FIELDS = ["*", "customer.*"].join(",");
|
|
159571
159950
|
MedusaEmployeeCapability = class extends EmployeeCapability {
|
|
159572
159951
|
constructor(config3, cache, context2, medusaApi, factory) {
|
|
@@ -159636,7 +160015,7 @@ var init_employee_capability3 = __esm({
|
|
|
159636
160015
|
return void 0;
|
|
159637
160016
|
}
|
|
159638
160017
|
async listEmployees(payload) {
|
|
159639
|
-
|
|
160018
|
+
debug27("listEmployees", payload);
|
|
159640
160019
|
try {
|
|
159641
160020
|
const companyId = await this.resolveCompanyId(payload.search.company.taxIdentifier);
|
|
159642
160021
|
if (!companyId) {
|
|
@@ -159679,7 +160058,7 @@ var init_employee_capability3 = __esm({
|
|
|
159679
160058
|
}
|
|
159680
160059
|
}
|
|
159681
160060
|
async getByEmail(payload) {
|
|
159682
|
-
|
|
160061
|
+
debug27("getByEmail", payload);
|
|
159683
160062
|
try {
|
|
159684
160063
|
const companyId = await this.resolveCompanyId(payload.company.taxIdentifier);
|
|
159685
160064
|
if (!companyId) {
|
|
@@ -159723,7 +160102,7 @@ var init_employee_capability3 = __esm({
|
|
|
159723
160102
|
);
|
|
159724
160103
|
}
|
|
159725
160104
|
async assignRole(payload) {
|
|
159726
|
-
|
|
160105
|
+
debug27("assignRole", payload);
|
|
159727
160106
|
try {
|
|
159728
160107
|
return await this.updateEmployeeRole(
|
|
159729
160108
|
payload.company,
|
|
@@ -159735,7 +160114,7 @@ var init_employee_capability3 = __esm({
|
|
|
159735
160114
|
}
|
|
159736
160115
|
}
|
|
159737
160116
|
async unassignRole(payload) {
|
|
159738
|
-
|
|
160117
|
+
debug27("unassignRole", payload);
|
|
159739
160118
|
try {
|
|
159740
160119
|
return await this.updateEmployeeRole(
|
|
159741
160120
|
payload.company,
|
|
@@ -159747,7 +160126,7 @@ var init_employee_capability3 = __esm({
|
|
|
159747
160126
|
}
|
|
159748
160127
|
}
|
|
159749
160128
|
async removeEmployee(payload) {
|
|
159750
|
-
|
|
160129
|
+
debug27("removeEmployee", payload);
|
|
159751
160130
|
try {
|
|
159752
160131
|
const companyId = await this.resolveCompanyId(payload.company.taxIdentifier);
|
|
159753
160132
|
if (!companyId) {
|
|
@@ -159886,16 +160265,16 @@ var init_employee_invitation_factory3 = __esm({
|
|
|
159886
160265
|
});
|
|
159887
160266
|
|
|
159888
160267
|
// packages/medusa/src/capabilities/employee-invitation.capability.ts
|
|
159889
|
-
var
|
|
160268
|
+
var import_debug28, debug28, EMPLOYEE_INVITATION_FIELDS, MedusaEmployeeInvitationCapability;
|
|
159890
160269
|
var init_employee_invitation_capability3 = __esm({
|
|
159891
160270
|
"packages/medusa/src/capabilities/employee-invitation.capability.ts"() {
|
|
159892
160271
|
"use strict";
|
|
159893
160272
|
init_esm2();
|
|
159894
160273
|
init_src();
|
|
159895
|
-
|
|
160274
|
+
import_debug28 = __toESM(require_src(), 1);
|
|
159896
160275
|
init_employee_invitation_factory3();
|
|
159897
160276
|
init_medusa_helpers();
|
|
159898
|
-
|
|
160277
|
+
debug28 = (0, import_debug28.default)("reactionary:medusa:employee-invitation");
|
|
159899
160278
|
EMPLOYEE_INVITATION_FIELDS = [
|
|
159900
160279
|
"id",
|
|
159901
160280
|
"email",
|
|
@@ -159952,7 +160331,7 @@ var init_employee_invitation_capability3 = __esm({
|
|
|
159952
160331
|
}
|
|
159953
160332
|
}
|
|
159954
160333
|
async inviteEmployee(payload) {
|
|
159955
|
-
|
|
160334
|
+
debug28("inviteEmployee", payload);
|
|
159956
160335
|
try {
|
|
159957
160336
|
const companyId = await this.resolveCompanyId(payload.company.taxIdentifier);
|
|
159958
160337
|
if (!companyId) {
|
|
@@ -159979,7 +160358,7 @@ var init_employee_invitation_capability3 = __esm({
|
|
|
159979
160358
|
}
|
|
159980
160359
|
}
|
|
159981
160360
|
async acceptInvitation(payload) {
|
|
159982
|
-
|
|
160361
|
+
debug28("acceptInvitation", { invitationIdentifier: payload.invitationIdentifier });
|
|
159983
160362
|
try {
|
|
159984
160363
|
const { invitationId } = parseInvitationKey(payload.invitationIdentifier.key);
|
|
159985
160364
|
const client = await this.medusaApi.getClient();
|
|
@@ -159999,7 +160378,7 @@ var init_employee_invitation_capability3 = __esm({
|
|
|
159999
160378
|
}
|
|
160000
160379
|
}
|
|
160001
160380
|
async revokeInvitation(payload) {
|
|
160002
|
-
|
|
160381
|
+
debug28("revokeInvitation", payload);
|
|
160003
160382
|
try {
|
|
160004
160383
|
const { companyId, invitationId } = parseInvitationKey(
|
|
160005
160384
|
payload.invitationIdentifier.key
|
|
@@ -160015,7 +160394,7 @@ var init_employee_invitation_capability3 = __esm({
|
|
|
160015
160394
|
}
|
|
160016
160395
|
}
|
|
160017
160396
|
async listInvitations(payload) {
|
|
160018
|
-
|
|
160397
|
+
debug28("listInvitations", payload);
|
|
160019
160398
|
try {
|
|
160020
160399
|
const client = await this.medusaApi.getClient();
|
|
160021
160400
|
const { pageNumber, pageSize } = payload.search.paginationOptions;
|
|
@@ -160088,13 +160467,13 @@ var init_employee_invitation_capability3 = __esm({
|
|
|
160088
160467
|
});
|
|
160089
160468
|
|
|
160090
160469
|
// packages/medusa/src/capabilities/identity.capability.ts
|
|
160091
|
-
var
|
|
160470
|
+
var import_debug29, debug29, MedusaIdentityCapability;
|
|
160092
160471
|
var init_identity_capability5 = __esm({
|
|
160093
160472
|
"packages/medusa/src/capabilities/identity.capability.ts"() {
|
|
160094
160473
|
"use strict";
|
|
160095
160474
|
init_src();
|
|
160096
|
-
|
|
160097
|
-
|
|
160475
|
+
import_debug29 = __toESM(require_src(), 1);
|
|
160476
|
+
debug29 = (0, import_debug29.default)("reactionary:medusa:identity");
|
|
160098
160477
|
MedusaIdentityCapability = class extends IdentityCapability {
|
|
160099
160478
|
config;
|
|
160100
160479
|
medusaApi;
|
|
@@ -160113,9 +160492,9 @@ var init_identity_capability5 = __esm({
|
|
|
160113
160492
|
const medusaClient = await this.medusaApi.getClient();
|
|
160114
160493
|
const token = await medusaClient.client.getToken();
|
|
160115
160494
|
if (!token) {
|
|
160116
|
-
|
|
160495
|
+
debug29("No active session token found, returning anonymous identity");
|
|
160117
160496
|
if (this.medusaApi.getSessionData().activeCartId) {
|
|
160118
|
-
|
|
160497
|
+
debug29("Active cart found in session without token, treating as guest session");
|
|
160119
160498
|
const identity3 = {
|
|
160120
160499
|
type: "Guest",
|
|
160121
160500
|
id: {
|
|
@@ -160131,7 +160510,7 @@ var init_identity_capability5 = __esm({
|
|
|
160131
160510
|
}
|
|
160132
160511
|
const customerResponse = await medusaClient.store.customer.retrieve();
|
|
160133
160512
|
if (customerResponse.customer) {
|
|
160134
|
-
|
|
160513
|
+
debug29("Customer authenticated:", customerResponse.customer.email);
|
|
160135
160514
|
const identity2 = {
|
|
160136
160515
|
id: {
|
|
160137
160516
|
userId: customerResponse.customer.id
|
|
@@ -160145,14 +160524,14 @@ var init_identity_capability5 = __esm({
|
|
|
160145
160524
|
this.updateIdentityContext(identity);
|
|
160146
160525
|
return success(identity);
|
|
160147
160526
|
} catch (error6) {
|
|
160148
|
-
|
|
160527
|
+
debug29("getSelf failed, returning anonymous identity:", error6);
|
|
160149
160528
|
const identity = this.createAnonymousIdentity();
|
|
160150
160529
|
this.updateIdentityContext(identity);
|
|
160151
160530
|
return success(identity);
|
|
160152
160531
|
}
|
|
160153
160532
|
}
|
|
160154
160533
|
async login(payload) {
|
|
160155
|
-
|
|
160534
|
+
debug29("Attempting login for user:", payload.username);
|
|
160156
160535
|
const identity = await this.medusaApi.login(
|
|
160157
160536
|
payload.username,
|
|
160158
160537
|
payload.password,
|
|
@@ -160162,13 +160541,13 @@ var init_identity_capability5 = __esm({
|
|
|
160162
160541
|
return success(identity);
|
|
160163
160542
|
}
|
|
160164
160543
|
async logout(_payload) {
|
|
160165
|
-
|
|
160544
|
+
debug29("Logging out user");
|
|
160166
160545
|
const identity = await this.medusaApi.logout(this.context);
|
|
160167
160546
|
this.updateIdentityContext(identity);
|
|
160168
160547
|
return success(identity);
|
|
160169
160548
|
}
|
|
160170
160549
|
async register(payload) {
|
|
160171
|
-
|
|
160550
|
+
debug29("Registering new user:", payload.username);
|
|
160172
160551
|
const nameParts = payload.username.split(".");
|
|
160173
160552
|
const firstName = nameParts[0] || "User";
|
|
160174
160553
|
const lastName = nameParts.slice(1).join(" ") || "Account";
|
|
@@ -160211,235 +160590,6 @@ var init_identity_capability5 = __esm({
|
|
|
160211
160590
|
}
|
|
160212
160591
|
});
|
|
160213
160592
|
|
|
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
160593
|
// packages/medusa/src/capabilities/inventory.capability.ts
|
|
160444
160594
|
var import_debug30, debug30, MedusaInventoryCapability;
|
|
160445
160595
|
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.53",
|
|
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.53",
|
|
16
|
+
"@reactionary/commercetools": "0.10.53",
|
|
17
|
+
"@reactionary/core": "0.10.53",
|
|
18
|
+
"@reactionary/fake": "0.10.53",
|
|
19
|
+
"@reactionary/magento": "0.10.53",
|
|
20
|
+
"@reactionary/medusa": "0.10.53",
|
|
21
|
+
"@reactionary/meilisearch": "0.10.53",
|
|
22
|
+
"@reactionary/unomi": "0.10.53",
|
|
23
23
|
"commander": "^15.0.0",
|
|
24
24
|
"dotenv": "^17.2.2",
|
|
25
25
|
"sitemap": "^9.0.1",
|