@reactionary/magento 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +11 -0
  2. package/capabilities/cart.capability.js +293 -0
  3. package/capabilities/category.capability.js +254 -0
  4. package/capabilities/identity.capability.js +107 -0
  5. package/capabilities/inventory.capability.js +84 -0
  6. package/capabilities/price.capability.js +72 -0
  7. package/capabilities/product-search.capability.js +113 -0
  8. package/capabilities/product.capability.js +146 -0
  9. package/core/client.js +321 -0
  10. package/core/initialize.js +176 -0
  11. package/core/initialize.types.js +13 -0
  12. package/factories/cart/cart.factory.js +135 -0
  13. package/factories/category/category.factory.js +48 -0
  14. package/factories/identity/identity.factory.js +12 -0
  15. package/factories/index.js +7 -0
  16. package/factories/inventory/inventory.factory.js +24 -0
  17. package/factories/price/price.factory.js +43 -0
  18. package/factories/product/product.factory.js +115 -0
  19. package/factories/product-search/product-search.factory.js +88 -0
  20. package/index.js +14 -0
  21. package/package.json +15 -0
  22. package/schema/capabilities.schema.js +31 -0
  23. package/schema/configuration.schema.js +13 -0
  24. package/schema/magento.schema.js +5 -0
  25. package/schema/magento.types.js +0 -0
  26. package/src/capabilities/cart.capability.d.ts +24 -0
  27. package/src/capabilities/category.capability.d.ts +22 -0
  28. package/src/capabilities/identity.capability.d.ts +13 -0
  29. package/src/capabilities/inventory.capability.d.ts +11 -0
  30. package/src/capabilities/price.capability.d.ts +12 -0
  31. package/src/capabilities/product-search.capability.d.ts +15 -0
  32. package/src/capabilities/product.capability.d.ts +14 -0
  33. package/src/core/client.d.ts +93 -0
  34. package/src/core/initialize.d.ts +5 -0
  35. package/src/core/initialize.types.d.ts +80 -0
  36. package/src/factories/cart/cart.factory.d.ts +20 -0
  37. package/src/factories/category/category.factory.d.ts +14 -0
  38. package/src/factories/identity/identity.factory.d.ts +7 -0
  39. package/src/factories/index.d.ts +7 -0
  40. package/src/factories/inventory/inventory.factory.d.ts +13 -0
  41. package/src/factories/price/price.factory.d.ts +15 -0
  42. package/src/factories/product/product.factory.d.ts +13 -0
  43. package/src/factories/product-search/product-search.factory.d.ts +12 -0
  44. package/src/index.d.ts +14 -0
  45. package/src/schema/capabilities.schema.d.ts +74 -0
  46. package/src/schema/configuration.schema.d.ts +11 -0
  47. package/src/schema/magento.schema.d.ts +5 -0
  48. package/src/schema/magento.types.d.ts +200 -0
@@ -0,0 +1,7 @@
1
+ export * from "./cart/cart.factory.js";
2
+ export * from "./category/category.factory.js";
3
+ export * from "./identity/identity.factory.js";
4
+ export * from "./inventory/inventory.factory.js";
5
+ export * from "./price/price.factory.js";
6
+ export * from "./product/product.factory.js";
7
+ export * from "./product-search/product-search.factory.js";
@@ -0,0 +1,24 @@
1
+ class MagentoInventoryFactory {
2
+ inventorySchema;
3
+ constructor(inventorySchema) {
4
+ this.inventorySchema = inventorySchema;
5
+ }
6
+ parseInventory(_context, data) {
7
+ const input = data;
8
+ const { sku, fulfillmentCenterKey, quantity } = input;
9
+ const identifier = {
10
+ variant: { sku },
11
+ fulfillmentCenter: { key: fulfillmentCenterKey }
12
+ };
13
+ const status = quantity > 0 ? "inStock" : "outOfStock";
14
+ const result = {
15
+ identifier,
16
+ quantity,
17
+ status
18
+ };
19
+ return this.inventorySchema.parse(result);
20
+ }
21
+ }
22
+ export {
23
+ MagentoInventoryFactory
24
+ };
@@ -0,0 +1,43 @@
1
+ class MagentoPriceFactory {
2
+ priceSchema;
3
+ constructor(priceSchema) {
4
+ this.priceSchema = priceSchema;
5
+ }
6
+ parsePrice(context, data, _options) {
7
+ const input = data;
8
+ const { product, sku, mode } = input;
9
+ const identifier = {
10
+ variant: { sku }
11
+ };
12
+ const basePrice = product.price ?? 0;
13
+ const specialPriceAttr = product.custom_attributes?.find((a) => a.attribute_code === "special_price");
14
+ const specialPrice = specialPriceAttr ? Number(specialPriceAttr.value) : void 0;
15
+ const finalPrice = mode === "customer" && specialPrice !== void 0 ? specialPrice : basePrice;
16
+ const unitPrice = {
17
+ value: finalPrice,
18
+ currency: context.languageContext.currencyCode || "USD"
19
+ };
20
+ const tieredPrices = [];
21
+ if (product.tier_prices) {
22
+ for (const tier of product.tier_prices) {
23
+ tieredPrices.push({
24
+ minimumQuantity: tier.qty,
25
+ price: {
26
+ value: tier.value,
27
+ currency: context.languageContext.currencyCode || "USD"
28
+ }
29
+ });
30
+ }
31
+ }
32
+ const result = {
33
+ identifier,
34
+ unitPrice,
35
+ onSale: false,
36
+ tieredPrices
37
+ };
38
+ return this.priceSchema.parse(result);
39
+ }
40
+ }
41
+ export {
42
+ MagentoPriceFactory
43
+ };
@@ -0,0 +1,115 @@
1
+ import {
2
+ CategoryIdentifierSchema,
3
+ ProductIdentifierSchema
4
+ } from "@reactionary/core";
5
+ function getCustomAttribute(product, code) {
6
+ if (!product.custom_attributes)
7
+ return void 0;
8
+ const found = product.custom_attributes.find((a) => a.attribute_code === code);
9
+ if (found?.value === null || found?.value === void 0)
10
+ return void 0;
11
+ return String(found.value);
12
+ }
13
+ function normalizeBaseUrl(baseUrl) {
14
+ return baseUrl.replace(/\/+$/, "");
15
+ }
16
+ function buildMagentoImageUrl(config, file) {
17
+ const mediaUrl = config.mediaUrl;
18
+ if (mediaUrl) {
19
+ return `${mediaUrl.replace(/\/+$/, "")}${file.startsWith("/") ? "" : "/"}${file}`;
20
+ }
21
+ const storeBase = `${normalizeBaseUrl(config.baseUrl)}`;
22
+ return `${storeBase}/media/catalog/product${file.startsWith("/") ? "" : "/"}${file}`;
23
+ }
24
+ class MagentoProductFactory {
25
+ constructor(productSchema, config) {
26
+ this.config = config;
27
+ this.productSchema = productSchema;
28
+ }
29
+ productSchema;
30
+ parseProduct(_context, data) {
31
+ const sku = data.sku;
32
+ const idKey = data.id !== void 0 ? String(data.id) : sku;
33
+ const identifier = ProductIdentifierSchema.parse({ key: idKey });
34
+ const name = data.name || sku;
35
+ const slug = getCustomAttribute(data, "url_key") ?? getCustomAttribute(data, "url_path") ?? "";
36
+ const description = getCustomAttribute(data, "description") ?? getCustomAttribute(data, "short_description") ?? "";
37
+ const categoryLinks = data.extension_attributes?.category_links;
38
+ const parentCategories = categoryLinks ? categoryLinks.map((c) => c.category_id).filter((x) => x !== null && x !== void 0).map((cid) => CategoryIdentifierSchema.parse({ key: String(cid) })) : [];
39
+ const sharedAttributes = this.parseAttributes(data);
40
+ const mainVariant = this.parseVariant(data);
41
+ const result = {
42
+ brand: getCustomAttribute(data, "manufacturer") ?? "",
43
+ description,
44
+ identifier,
45
+ longDescription: "",
46
+ mainVariant,
47
+ manufacturer: getCustomAttribute(data, "manufacturer") ?? "",
48
+ name,
49
+ options: [],
50
+ parentCategories,
51
+ published: true,
52
+ sharedAttributes,
53
+ slug,
54
+ variants: []
55
+ };
56
+ return this.productSchema.parse(result);
57
+ }
58
+ parseVariant(product) {
59
+ const sku = product.sku;
60
+ const ean = getCustomAttribute(product, "ean") ?? getCustomAttribute(product, "gtin") ?? getCustomAttribute(product, "barcode") ?? "";
61
+ const upc = getCustomAttribute(product, "upc") ?? "";
62
+ const images = (product.media_gallery_entries ?? []).filter((m) => m.file.length > 0).map((m) => ({
63
+ sourceUrl: buildMagentoImageUrl(this.config, m.file),
64
+ altText: product.name || sku
65
+ }));
66
+ const options = [];
67
+ return {
68
+ identifier: { sku },
69
+ name: product.name || sku,
70
+ upc,
71
+ ean,
72
+ images,
73
+ options,
74
+ gtin: ean,
75
+ barcode: ean
76
+ };
77
+ }
78
+ createSynthAttribute(key, name, value) {
79
+ const attributeIdentifier = { key };
80
+ const valueIdentifier = { key: `${key}-${value}` };
81
+ return {
82
+ identifier: attributeIdentifier,
83
+ name,
84
+ group: "",
85
+ values: [
86
+ {
87
+ identifier: valueIdentifier,
88
+ label: String(value),
89
+ value
90
+ }
91
+ ]
92
+ };
93
+ }
94
+ parseAttributes(product) {
95
+ const sharedAttributes = [];
96
+ if (!product.custom_attributes)
97
+ return sharedAttributes;
98
+ for (const entry of product.custom_attributes) {
99
+ const key = entry.attribute_code;
100
+ const value = entry.value;
101
+ if (!key)
102
+ continue;
103
+ if (key === "description" || key === "short_description")
104
+ continue;
105
+ if (value === null || value === void 0)
106
+ continue;
107
+ const stringValue = typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value) : JSON.stringify(value);
108
+ sharedAttributes.push(this.createSynthAttribute(key, key, stringValue));
109
+ }
110
+ return sharedAttributes;
111
+ }
112
+ }
113
+ export {
114
+ MagentoProductFactory
115
+ };
@@ -0,0 +1,88 @@
1
+ import {
2
+ ImageSchema,
3
+ ProductSearchResultItemVariantSchema,
4
+ ProductVariantIdentifierSchema
5
+ } from "@reactionary/core";
6
+ function getCustomAttribute(product, code) {
7
+ if (!product.custom_attributes)
8
+ return void 0;
9
+ const found = product.custom_attributes.find((a) => a.attribute_code === code);
10
+ if (found?.value === null || found?.value === void 0)
11
+ return void 0;
12
+ return String(found.value);
13
+ }
14
+ function normalizeBaseUrl(baseUrl) {
15
+ return baseUrl.replace(/\/+$/, "");
16
+ }
17
+ function buildMagentoImageUrl(config, file) {
18
+ const mediaUrl = config["mediaUrl"];
19
+ if (mediaUrl) {
20
+ return `${mediaUrl.replace(/\/+$/, "")}${file.startsWith("/") ? "" : "/"}${file}`;
21
+ }
22
+ const storeBase = normalizeBaseUrl(config.baseUrl);
23
+ return `${storeBase}/media/catalog/product${file.startsWith("/") ? "" : "/"}${file}`;
24
+ }
25
+ class MagentoProductSearchFactory {
26
+ constructor(productSearchResultSchema, config) {
27
+ this.config = config;
28
+ this.productSearchResultSchema = productSearchResultSchema;
29
+ }
30
+ productSearchResultSchema;
31
+ parseSearchResult(context, data, query) {
32
+ const pageSize = query.search.paginationOptions.pageSize;
33
+ const currentPage = query.search.paginationOptions.pageNumber;
34
+ const items = (data.items || []).map(
35
+ (p) => this.parseProductSearchResultItem(context, p)
36
+ );
37
+ const totalCount = data.total_count ?? 0;
38
+ const totalPages = Math.max(1, Math.ceil(totalCount / pageSize));
39
+ const result = {
40
+ identifier: {
41
+ ...query.search
42
+ },
43
+ pageNumber: currentPage,
44
+ pageSize,
45
+ totalCount,
46
+ totalPages,
47
+ items,
48
+ facets: []
49
+ };
50
+ return this.productSearchResultSchema.parse(result);
51
+ }
52
+ parseProductSearchResultItem(_context, product) {
53
+ const idKey = product.id !== void 0 ? String(product.id) : product.sku;
54
+ const identifier = { key: idKey };
55
+ const slug = getCustomAttribute(product, "url_key") ?? getCustomAttribute(product, "url_path") ?? "";
56
+ const name = product.name || product.sku;
57
+ const variants = [];
58
+ if (product.sku) {
59
+ variants.push(this.parseVariant(product, product));
60
+ }
61
+ return {
62
+ identifier,
63
+ name,
64
+ slug,
65
+ variants
66
+ };
67
+ }
68
+ parseVariant(variant, product) {
69
+ const media = product.media_gallery_entries;
70
+ const firstImage = media && media.length > 0 ? media[0].file : null;
71
+ const img = firstImage ? ImageSchema.parse({
72
+ sourceUrl: buildMagentoImageUrl(this.config, firstImage),
73
+ altText: product.name || void 0
74
+ }) : ImageSchema.parse({
75
+ sourceUrl: "",
76
+ altText: product.name || void 0
77
+ });
78
+ return ProductSearchResultItemVariantSchema.parse({
79
+ variant: ProductVariantIdentifierSchema.parse({
80
+ sku: variant.sku
81
+ }),
82
+ image: img
83
+ });
84
+ }
85
+ }
86
+ export {
87
+ MagentoProductSearchFactory
88
+ };
package/index.js ADDED
@@ -0,0 +1,14 @@
1
+ export * from "./schema/configuration.schema.js";
2
+ export * from "./schema/capabilities.schema.js";
3
+ export * from "./schema/magento.schema.js";
4
+ export * from "./core/initialize.js";
5
+ export * from "./core/initialize.types.js";
6
+ export * from "./core/client.js";
7
+ export * from "./factories/index.js";
8
+ export * from "./capabilities/product.capability.js";
9
+ export * from "./capabilities/product-search.capability.js";
10
+ export * from "./capabilities/category.capability.js";
11
+ export * from "./capabilities/inventory.capability.js";
12
+ export * from "./capabilities/price.capability.js";
13
+ export * from "./capabilities/identity.capability.js";
14
+ export * from "./capabilities/cart.capability.js";
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@reactionary/magento",
3
+ "version": "0.0.1",
4
+ "private": false,
5
+ "type": "module",
6
+ "main": "./index.js",
7
+ "types": "./src/index.d.ts",
8
+ "dependencies": {
9
+ "@reactionary/core": "0.0.1",
10
+ "zod": "4.1.9",
11
+ "debug": "^4.4.3"
12
+ },
13
+ "sideEffets": false
14
+
15
+ }
@@ -0,0 +1,31 @@
1
+ import { CapabilitiesSchema } from "@reactionary/core";
2
+ import * as z from "zod";
3
+ const OverridableCapabilitySchema = z.looseObject({
4
+ enabled: z.boolean(),
5
+ factory: z.unknown().optional(),
6
+ capability: z.unknown().optional()
7
+ });
8
+ const DirectCapabilitySchema = z.looseObject({
9
+ enabled: z.boolean(),
10
+ capability: z.unknown().optional()
11
+ });
12
+ const MagentoCapabilitiesSchema = CapabilitiesSchema.pick({
13
+ product: true,
14
+ productSearch: true,
15
+ category: true,
16
+ inventory: true,
17
+ price: true,
18
+ identity: true,
19
+ cart: true
20
+ }).extend({
21
+ product: OverridableCapabilitySchema.optional(),
22
+ productSearch: OverridableCapabilitySchema.optional(),
23
+ cart: OverridableCapabilitySchema.optional(),
24
+ category: OverridableCapabilitySchema.optional(),
25
+ price: OverridableCapabilitySchema.optional(),
26
+ inventory: OverridableCapabilitySchema.optional(),
27
+ identity: DirectCapabilitySchema.optional()
28
+ }).partial();
29
+ export {
30
+ MagentoCapabilitiesSchema
31
+ };
@@ -0,0 +1,13 @@
1
+ import * as z from "zod";
2
+ const MagentoConfigurationSchema = z.looseObject({
3
+ adminApiKey: z.string().meta({ description: "The API key for Magento admin operations. Needed for the few tasks that require admin access." }),
4
+ baseUrl: z.string().meta({ description: "The base URL for the Magento installation." }),
5
+ mediaUrl: z.string().optional().meta({ description: "The base URL for media files. If not provided, it will be derived from the baseUrl." }),
6
+ defaultCurrency: z.string().default(""),
7
+ rootCategoryId: z.string().default("2").meta({ description: 'The ID of the root category in Magento. Typically "2" for the default Magento setup.' }),
8
+ allCurrencies: z.array(z.string()),
9
+ storeCode: z.string().default("")
10
+ });
11
+ export {
12
+ MagentoConfigurationSchema
13
+ };
@@ -0,0 +1,5 @@
1
+ import { CartIdentifierSchema } from "@reactionary/core";
2
+ const MagentoCartIdentifierSchema = CartIdentifierSchema.extend({});
3
+ export {
4
+ MagentoCartIdentifierSchema
5
+ };
File without changes
@@ -0,0 +1,24 @@
1
+ import { type Cache, type CartFactory, type CartFactoryCartOutput, type CartFactoryWithOutput, type CartIdentifier, type CartMutationApplyCoupon, type CartMutationChangeCurrency, type CartMutationCreateCart, type CartMutationDeleteCart, type CartMutationItemAdd, type CartMutationItemQuantityChange, type CartMutationItemRemove, type CartMutationRemoveCoupon, type CartMutationRenameCart, type CartPaginatedSearchResult, type CartQueryById, type CartQueryList, type NotFoundError, type RequestContext, type Result, CartCapability } from '@reactionary/core';
2
+ import type { MagentoClient } from '../core/client.js';
3
+ import type { MagentoConfiguration } from '../schema/configuration.schema.js';
4
+ import type { MagentoCartFactory } from '../factories/cart/cart.factory.js';
5
+ export declare class MagentoCartCapability<TFactory extends CartFactory = MagentoCartFactory> extends CartCapability<CartFactoryCartOutput<TFactory>> {
6
+ magentoApi: MagentoClient;
7
+ protected config: MagentoConfiguration;
8
+ protected factory: CartFactoryWithOutput<TFactory>;
9
+ constructor(config: MagentoConfiguration, cache: Cache, context: RequestContext, magentoApi: MagentoClient, factory: CartFactoryWithOutput<TFactory>);
10
+ getById(payload: CartQueryById): Promise<Result<CartFactoryCartOutput<TFactory>, NotFoundError>>;
11
+ add(payload: CartMutationItemAdd): Promise<Result<CartFactoryCartOutput<TFactory>>>;
12
+ remove(payload: CartMutationItemRemove): Promise<Result<CartFactoryCartOutput<TFactory>>>;
13
+ changeQuantity(payload: CartMutationItemQuantityChange): Promise<Result<CartFactoryCartOutput<TFactory>>>;
14
+ getActiveCartId(): Promise<Result<CartIdentifier, NotFoundError>>;
15
+ deleteCart(_payload: CartMutationDeleteCart): Promise<Result<void>>;
16
+ applyCouponCode(payload: CartMutationApplyCoupon): Promise<Result<CartFactoryCartOutput<TFactory>>>;
17
+ removeCouponCode(payload: CartMutationRemoveCoupon): Promise<Result<CartFactoryCartOutput<TFactory>>>;
18
+ changeCurrency(_payload: CartMutationChangeCurrency): Promise<Result<CartFactoryCartOutput<TFactory>>>;
19
+ listCarts(_payload: CartQueryList): Promise<Result<CartPaginatedSearchResult>>;
20
+ createCart(_payload: CartMutationCreateCart): Promise<Result<CartFactoryCartOutput<TFactory>>>;
21
+ renameCart(_payload: CartMutationRenameCart): Promise<Result<CartFactoryCartOutput<TFactory>>>;
22
+ protected createNewCart(): Promise<CartIdentifier>;
23
+ protected getCartWithTotals(cartId: string): Promise<Record<string, unknown>>;
24
+ }
@@ -0,0 +1,22 @@
1
+ import type { Cache, CategoryFactory, CategoryFactoryCategoryOutput, CategoryFactoryPaginatedOutput, CategoryFactoryWithOutput } from '@reactionary/core';
2
+ import { CategoryCapability, type CategoryQueryById, type CategoryQueryBySlug, type CategoryQueryForBreadcrumb, type CategoryQueryForChildCategories, type CategoryQueryForTopCategories, type NotFoundError, type RequestContext, type Result } from '@reactionary/core';
3
+ import type { MagentoConfiguration } from '../schema/configuration.schema.js';
4
+ import type { Magento, MagentoClient } from '../core/client.js';
5
+ import type { MagentoCategoryFactory } from '../factories/category/category.factory.js';
6
+ import type { MagentoCategory, MagentoCategorySearchResult } from '../schema/magento.types.js';
7
+ export declare class MagentoCategoryCapability<TFactory extends CategoryFactory = MagentoCategoryFactory> extends CategoryCapability<CategoryFactoryCategoryOutput<TFactory>, CategoryFactoryPaginatedOutput<TFactory>> {
8
+ magentoApi: MagentoClient;
9
+ protected config: MagentoConfiguration;
10
+ protected factory: CategoryFactoryWithOutput<TFactory>;
11
+ constructor(config: MagentoConfiguration, cache: Cache, context: RequestContext, magentoApi: MagentoClient, factory: CategoryFactoryWithOutput<TFactory>);
12
+ getById(payload: CategoryQueryById): Promise<Result<CategoryFactoryCategoryOutput<TFactory>, NotFoundError>>;
13
+ getBySlug(payload: CategoryQueryBySlug): Promise<Result<CategoryFactoryCategoryOutput<TFactory>, NotFoundError>>;
14
+ getBreadcrumbPathToCategory(payload: CategoryQueryForBreadcrumb): Promise<Result<CategoryFactoryCategoryOutput<TFactory>[]>>;
15
+ findChildCategories(payload: CategoryQueryForChildCategories): Promise<Result<CategoryFactoryPaginatedOutput<TFactory>>>;
16
+ findTopCategories(payload: CategoryQueryForTopCategories): Promise<Result<CategoryFactoryPaginatedOutput<TFactory>>>;
17
+ protected cacheCategoryKeyToIdMapping(key: string, id: string): Promise<void>;
18
+ protected translateCategoryKeyToMagentoId(client: Magento, key: string): Promise<string | null>;
19
+ protected translateMagentoIdToCategoryKey(magentoId: string): Promise<string | null>;
20
+ protected cleanupParentPointersForCategory(category: MagentoCategory): Promise<MagentoCategory>;
21
+ protected cleanupParentPointersForPaginatedResult(paginatedResult: MagentoCategorySearchResult): Promise<MagentoCategorySearchResult>;
22
+ }
@@ -0,0 +1,13 @@
1
+ import { type Identity, type IdentityMutationLogin, type IdentityMutationLogout, type IdentityMutationRegister, type IdentityQuerySelf, type RequestContext, type Cache, IdentityCapability, type AnonymousIdentity, type Result } from '@reactionary/core';
2
+ import type { MagentoClient } from '../core/client.js';
3
+ import type { MagentoConfiguration } from '../schema/configuration.schema.js';
4
+ export declare class MagentoIdentityCapability extends IdentityCapability {
5
+ magentoApi: MagentoClient;
6
+ protected config: MagentoConfiguration;
7
+ constructor(config: MagentoConfiguration, cache: Cache, context: RequestContext, magentoApi: MagentoClient);
8
+ protected createAnonymousIdentity(): AnonymousIdentity;
9
+ getSelf(_payload: IdentityQuerySelf): Promise<Result<Identity>>;
10
+ login(payload: IdentityMutationLogin): Promise<Result<Identity>>;
11
+ logout(_payload: IdentityMutationLogout): Promise<Result<Identity>>;
12
+ register(payload: IdentityMutationRegister): Promise<Result<Identity>>;
13
+ }
@@ -0,0 +1,11 @@
1
+ import { type InventoryQueryBySKU, type RequestContext, type Cache, InventoryCapability, type InventoryFactory, type InventoryFactoryOutput, type InventoryFactoryWithOutput, type NotFoundError, type Result } from '@reactionary/core';
2
+ import type { MagentoConfiguration } from '../schema/configuration.schema.js';
3
+ import type { MagentoClient } from '../core/client.js';
4
+ import type { MagentoInventoryFactory } from '../factories/inventory/inventory.factory.js';
5
+ export declare class MagentoInventoryCapability<TFactory extends InventoryFactory = MagentoInventoryFactory> extends InventoryCapability<InventoryFactoryOutput<TFactory>> {
6
+ magentoApi: MagentoClient;
7
+ protected config: MagentoConfiguration;
8
+ protected factory: InventoryFactoryWithOutput<TFactory>;
9
+ constructor(config: MagentoConfiguration, cache: Cache, context: RequestContext, magentoApi: MagentoClient, factory: InventoryFactoryWithOutput<TFactory>);
10
+ getBySKU(payload: InventoryQueryBySKU): Promise<Result<InventoryFactoryOutput<TFactory>, NotFoundError>>;
11
+ }
@@ -0,0 +1,12 @@
1
+ import { PriceCapability, type Cache, type CustomerPriceQuery, type ListPriceQuery, type PriceFactory, type PriceFactoryOutput, type PriceFactoryWithOutput, type RequestContext, type Result } from '@reactionary/core';
2
+ import type { MagentoClient } from '../core/client.js';
3
+ import type { MagentoConfiguration } from '../schema/configuration.schema.js';
4
+ import type { MagentoPriceFactory } from '../factories/price/price.factory.js';
5
+ export declare class MagentoPriceCapability<TFactory extends PriceFactory = MagentoPriceFactory> extends PriceCapability<PriceFactoryOutput<TFactory>> {
6
+ magentoApi: MagentoClient;
7
+ protected config: MagentoConfiguration;
8
+ protected factory: PriceFactoryWithOutput<TFactory>;
9
+ constructor(config: MagentoConfiguration, cache: Cache, context: RequestContext, magentoApi: MagentoClient, factory: PriceFactoryWithOutput<TFactory>);
10
+ getListPrice(payload: ListPriceQuery): Promise<Result<PriceFactoryOutput<TFactory>>>;
11
+ getCustomerPrice(payload: CustomerPriceQuery): Promise<Result<PriceFactoryOutput<TFactory>>>;
12
+ }
@@ -0,0 +1,15 @@
1
+ import { ProductSearchCapability, type Cache, type FacetIdentifier, type FacetValueIdentifier, type ProductSearchFactory, type ProductSearchFactoryOutput, type ProductSearchFactoryWithOutput, type ProductSearchQueryByTerm, type ProductSearchQueryCreateNavigationFilter, type ProductSearchResultFacet, type ProductSearchResultFacetValue, type RequestContext, type Result } from '@reactionary/core';
2
+ import type { MagentoConfiguration } from '../schema/configuration.schema.js';
3
+ import type { MagentoClient } from '../core/client.js';
4
+ import type { MagentoProductSearchFactory } from '../factories/product-search/product-search.factory.js';
5
+ export declare class MagentoProductSearchCapability<TFactory extends ProductSearchFactory = MagentoProductSearchFactory> extends ProductSearchCapability<ProductSearchFactoryOutput<TFactory>> {
6
+ magentoApi: MagentoClient;
7
+ protected config: MagentoConfiguration;
8
+ protected factory: ProductSearchFactoryWithOutput<TFactory>;
9
+ constructor(config: MagentoConfiguration, cache: Cache, context: RequestContext, magentoApi: MagentoClient, factory: ProductSearchFactoryWithOutput<TFactory>);
10
+ queryByTerm(payload: ProductSearchQueryByTerm): Promise<Result<ProductSearchFactoryOutput<TFactory>>>;
11
+ createCategoryNavigationFilter(payload: ProductSearchQueryCreateNavigationFilter): Promise<Result<FacetValueIdentifier>>;
12
+ protected parseFacetValue(_facetValueIdentifier: FacetValueIdentifier, _label: string, _count: number): ProductSearchResultFacetValue;
13
+ protected parseFacet(_facetIdentifier: FacetIdentifier, _facetValue: unknown): ProductSearchResultFacet;
14
+ protected parseVariant(): never;
15
+ }
@@ -0,0 +1,14 @@
1
+ import type { Cache, NotFoundError, ProductFactory, ProductFactoryOutput, ProductFactoryWithOutput, ProductQueryById, ProductQueryBySKU, ProductQueryBySlug, RequestContext, Result } from '@reactionary/core';
2
+ import { ProductCapability } from '@reactionary/core';
3
+ import type { MagentoClient } from '../core/client.js';
4
+ import type { MagentoConfiguration } from '../schema/configuration.schema.js';
5
+ import type { MagentoProductFactory } from '../factories/product/product.factory.js';
6
+ export declare class MagentoProductCapability<TFactory extends ProductFactory = MagentoProductFactory> extends ProductCapability<ProductFactoryOutput<TFactory>> {
7
+ magentoApi: MagentoClient;
8
+ protected config: MagentoConfiguration;
9
+ protected factory: ProductFactoryWithOutput<TFactory>;
10
+ constructor(config: MagentoConfiguration, cache: Cache, context: RequestContext, magentoApi: MagentoClient, factory: ProductFactoryWithOutput<TFactory>);
11
+ getById(payload: ProductQueryById): Promise<Result<ProductFactoryOutput<TFactory>>>;
12
+ getBySlug(payload: ProductQueryBySlug): Promise<Result<ProductFactoryOutput<TFactory>, NotFoundError>>;
13
+ getBySKU(payload: ProductQueryBySKU): Promise<Result<ProductFactoryOutput<TFactory>>>;
14
+ }
@@ -0,0 +1,93 @@
1
+ import type { MagentoConfiguration } from '../schema/configuration.schema.js';
2
+ import type { RequestContext } from '@reactionary/core';
3
+ export declare const SESSION_KEY = "MAGENTO_PROVIDER";
4
+ export interface MagentoCustomStorage {
5
+ getItem(key: string): Promise<string | null>;
6
+ setItem(key: string, value: string): Promise<void>;
7
+ removeItem(key: string): Promise<void>;
8
+ }
9
+ export declare class RequestContextTokenStore implements MagentoCustomStorage {
10
+ protected context: RequestContext;
11
+ keyPrefix: string;
12
+ constructor(context: RequestContext, keyPrefix?: string);
13
+ private ensureNamespace;
14
+ getItem(key: string): Promise<string | null>;
15
+ setItem(key: string, value: string): Promise<void>;
16
+ removeItem(key: string): Promise<void>;
17
+ }
18
+ declare class MagentoRest {
19
+ private baseUrl;
20
+ private storeCode;
21
+ private getAuthHeader;
22
+ protected apiUrl: string;
23
+ constructor(baseUrl: string, storeCode: string, getAuthHeader: () => Promise<Record<string, string>>);
24
+ private normalizeUrl;
25
+ request<T>(method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE', path: string, body?: unknown): Promise<T>;
26
+ }
27
+ export declare class Magento {
28
+ private rest;
29
+ private tokenStore;
30
+ constructor(rest: MagentoRest, tokenStore: RequestContextTokenStore);
31
+ auth: {
32
+ login: (email: string, password: string) => Promise<string>;
33
+ logout: () => Promise<void>;
34
+ };
35
+ store: {
36
+ customer: {
37
+ register: (customer: any, password?: string) => Promise<any>;
38
+ me: () => Promise<any>;
39
+ };
40
+ product: {
41
+ getBySKU: (sku: string) => Promise<any>;
42
+ search: (params: URLSearchParams) => Promise<any>;
43
+ };
44
+ category: {
45
+ getById: (categoryId: string) => Promise<any>;
46
+ getByExternalId: (externalId: string) => Promise<any>;
47
+ list: (params: URLSearchParams) => Promise<any>;
48
+ };
49
+ inventory: {
50
+ getStockStatus: (sku: string) => Promise<any>;
51
+ getSourceItems: (params: URLSearchParams) => Promise<any>;
52
+ };
53
+ cart: {
54
+ create: (customerToken?: string | null) => Promise<string>;
55
+ get: (cartId?: string | null, customerToken?: string | null) => Promise<any>;
56
+ getTotals: (cartId?: string | null, customerToken?: string | null) => Promise<any>;
57
+ addItem: (cartId: string | null, item: any, customerToken?: string | null) => Promise<any>;
58
+ updateItem: (cartId: string | null, itemId: number, item: any, customerToken?: string | null) => Promise<any>;
59
+ removeItem: (cartId: string | null, itemId: number, customerToken?: string | null) => Promise<any>;
60
+ applyCoupon: (cartId: string | null, couponCode: string, customerToken?: string | null) => Promise<any>;
61
+ removeCoupon: (cartId: string | null, customerToken?: string | null) => Promise<any>;
62
+ };
63
+ };
64
+ }
65
+ export declare class MagentoAdminClient {
66
+ protected rest: MagentoRest;
67
+ protected client: Magento;
68
+ constructor(config: MagentoConfiguration, context: RequestContext);
69
+ getClient(): Promise<Magento>;
70
+ }
71
+ export declare class MagentoClient {
72
+ protected config: MagentoConfiguration;
73
+ protected tokenStore: RequestContextTokenStore;
74
+ protected rest: MagentoRest;
75
+ protected client: Promise<Magento> | undefined;
76
+ constructor(config: MagentoConfiguration, context: RequestContext);
77
+ getClient(): Promise<Magento>;
78
+ login(email: string, password: string): Promise<string>;
79
+ logout(): Promise<void>;
80
+ getMe(): Promise<any>;
81
+ register(customer: any, password?: string): Promise<any>;
82
+ getProductBySKU(sku: string): Promise<any>;
83
+ resolveProductForSKU(sku: string): Promise<any>;
84
+ createCart(): Promise<string>;
85
+ getCart(cartId?: string | null): Promise<any>;
86
+ getCartTotals(cartId?: string | null): Promise<any>;
87
+ addItemToCart(cartId: string | null, item: any): Promise<any>;
88
+ updateCartItem(cartId: string | null, itemId: number, item: any): Promise<any>;
89
+ removeCartItem(cartId: string | null, itemId: number): Promise<any>;
90
+ applyCoupon(cartId: string | null, couponCode: string): Promise<any>;
91
+ removeCoupon(cartId: string | null): Promise<any>;
92
+ }
93
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { Cache, RequestContext } from '@reactionary/core';
2
+ import { type MagentoCapabilities } from '../schema/capabilities.schema.js';
3
+ import { type MagentoConfiguration } from '../schema/configuration.schema.js';
4
+ import { type MagentoClientFromCapabilities } from './initialize.types.js';
5
+ export declare function withMagentoCapabilities<T extends MagentoCapabilities>(configuration: MagentoConfiguration, capabilities: T): (cache: Cache, context: RequestContext) => MagentoClientFromCapabilities<T>;