@merkaly/api 0.25.2 → 0.26.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.
@@ -47,11 +47,11 @@ export class SearchValidator extends ReadValidator {
47
47
  filters = {};
48
48
  }
49
49
  __decorate([
50
- (0, class_transformer_1.Transform)(({ value }) => {
50
+ (0, class_transformer_1.Transform)(({ key, value }) => {
51
51
  if (!value) {
52
52
  return new PaginationValidator();
53
53
  }
54
- const parsed = (0, class_validator_1.isObject)(value) ? value : JSON.parse(value);
54
+ const parsed = (0, class_validator_1.isObject)(value) ? value : parseQueryJson(key, value);
55
55
  return (0, class_transformer_1.plainToInstance)(PaginationValidator, parsed);
56
56
  }),
57
57
  (0, class_validator_1.ValidateNested)(),
@@ -60,23 +60,54 @@ __decorate([
60
60
  __metadata("design:type", PaginationValidator)
61
61
  ], SearchValidator.prototype, "pagination", void 0);
62
62
  __decorate([
63
- (0, class_transformer_1.Transform)(({ value }) => transformStructuredValue(value)),
63
+ (0, class_transformer_1.Transform)(({ key, value }) => assertSortOrder(transformStructuredValue(key, value))),
64
64
  (0, class_validator_1.IsOptional)(),
65
65
  __metadata("design:type", Object)
66
66
  ], SearchValidator.prototype, "sort", void 0);
67
67
  __decorate([
68
- (0, class_transformer_1.Transform)(({ value }) => transformStructuredValue(value)),
68
+ (0, class_transformer_1.Transform)(({ key, value }) => transformStructuredValue(key, value)),
69
69
  (0, class_validator_1.IsOptional)(),
70
70
  __metadata("design:type", Object)
71
71
  ], SearchValidator.prototype, "filters", void 0);
72
- function transformStructuredValue(value) {
72
+ class QueryValidationError extends Error {
73
+ statusCode = 400;
74
+ }
75
+ const FORBIDDEN_OPERATORS = new Set(['$where', '$function', '$accumulator']);
76
+ const SORT_ORDERS = new Set([1, -1, 'asc', 'desc', 'ascending', 'descending']);
77
+ function assertSortOrder(sort) {
78
+ if (!sort)
79
+ return sort;
80
+ if (!(0, class_validator_1.isObject)(sort) || (0, class_validator_1.isArray)(sort))
81
+ throw new QueryValidationError('sort must be an object');
82
+ for (const [field, order] of Object.entries(sort)) {
83
+ if (!SORT_ORDERS.has(order))
84
+ throw new QueryValidationError(`sort.${field} must be 1, -1, asc or desc`);
85
+ }
86
+ return sort;
87
+ }
88
+ function parseQueryJson(key, value) {
89
+ if (!(0, class_validator_1.isJSON)(value))
90
+ throw new QueryValidationError(`${key} must be valid JSON`);
91
+ return JSON.parse(value);
92
+ }
93
+ function assertNoForbiddenOperators(key, value) {
94
+ if ((0, class_validator_1.isArray)(value))
95
+ return value.forEach((item) => assertNoForbiddenOperators(key, item));
96
+ if (!(0, class_validator_1.isObject)(value))
97
+ return;
98
+ for (const [field, nested] of Object.entries(value)) {
99
+ if (FORBIDDEN_OPERATORS.has(field))
100
+ throw new QueryValidationError(`${key} must not use ${field}`);
101
+ assertNoForbiddenOperators(key, nested);
102
+ }
103
+ }
104
+ function transformStructuredValue(key, value) {
73
105
  if (!value) {
74
106
  return undefined;
75
107
  }
76
- if ((0, class_validator_1.isObject)(value) || (0, class_validator_1.isArray)(value)) {
77
- return value;
78
- }
79
- return JSON.parse(value);
108
+ const parsed = (0, class_validator_1.isObject)(value) || (0, class_validator_1.isArray)(value) ? value : parseQueryJson(key, value);
109
+ assertNoForbiddenOperators(key, parsed);
110
+ return parsed;
80
111
  }
81
112
  function transformJoinsIntoPopulate(value) {
82
113
  function transform(value) {
@@ -1,4 +1,5 @@
1
1
  import { Schema as MongoSchema } from 'mongoose';
2
+ import { PaymentChargeAccountEnum } from '../../integration/payment';
2
3
  import { FinancePaymentMethodEnum } from './payment.enum.js';
3
4
  export declare class FinancePaymentGatewayPixEntity {
4
5
  qrCode?: string | null;
@@ -29,6 +30,7 @@ export declare const FinancePaymentGatewayCardSchema: MongoSchema<FinancePayment
29
30
  export declare class FinancePaymentGatewayEntity {
30
31
  provider: string;
31
32
  reference?: string | null;
33
+ account?: PaymentChargeAccountEnum | null;
32
34
  method: FinancePaymentMethodEnum;
33
35
  status: string;
34
36
  message?: string | null;
@@ -7,3 +7,7 @@ export declare enum PaymentChargeStatusEnum {
7
7
  EXPIRED = "EXPIRED",
8
8
  REFUNDED = "REFUNDED"
9
9
  }
10
+ export declare enum PaymentChargeAccountEnum {
11
+ MAIN = "MAIN",
12
+ SUBCONTA = "SUBCONTA"
13
+ }
@@ -8,3 +8,8 @@ export var PaymentChargeStatusEnum;
8
8
  PaymentChargeStatusEnum["EXPIRED"] = "EXPIRED";
9
9
  PaymentChargeStatusEnum["REFUNDED"] = "REFUNDED";
10
10
  })(PaymentChargeStatusEnum || (PaymentChargeStatusEnum = {}));
11
+ export var PaymentChargeAccountEnum;
12
+ (function (PaymentChargeAccountEnum) {
13
+ PaymentChargeAccountEnum["MAIN"] = "MAIN";
14
+ PaymentChargeAccountEnum["SUBCONTA"] = "SUBCONTA";
15
+ })(PaymentChargeAccountEnum || (PaymentChargeAccountEnum = {}));
@@ -5,7 +5,6 @@ import type { CatalogBrandEntity } from '../brand';
5
5
  import type { CatalogCategoryEntity } from '../category';
6
6
  import type { CatalogVariantEntity } from '../variant';
7
7
  import type { ContactVendorEntity } from '../../../contact/vendor';
8
- import type { IntegrationSupplierEntity } from '../../../integration/supplier';
9
8
  export declare class CatalogProductPropertyEntity {
10
9
  name: string;
11
10
  value: string;
@@ -25,7 +24,6 @@ export declare class CatalogProductEntity extends AbstractEntity {
25
24
  name: string;
26
25
  description?: string;
27
26
  active: boolean;
28
- supplier?: IntegrationSupplierEntity;
29
27
  vendor?: ContactVendorEntity;
30
28
  externalProductId?: string;
31
29
  handlingDays?: number | null;
@@ -33,13 +31,12 @@ export declare class CatalogProductEntity extends AbstractEntity {
33
31
  ratingValue?: number | null;
34
32
  ratingCount?: number | null;
35
33
  soldCount?: number | null;
36
- reviewCount?: number | null;
37
34
  variant: CatalogVariantEntity;
38
35
  readonly supplierPrice: number;
39
36
  readonly retailPrice: number;
40
37
  category?: CatalogCategoryEntity;
41
38
  brand?: CatalogBrandEntity;
42
- hashtags: string[];
39
+ posterId?: string | null;
43
40
  readonly picture: AssetEntity;
44
41
  readonly assets: AssetEntity[];
45
42
  readonly options: {
@@ -7,7 +7,6 @@ declare class ProductMetadataRequestValidator extends AbstractRequestValidator {
7
7
  description?: string;
8
8
  category?: string;
9
9
  brand?: string;
10
- hashtags?: string[];
11
10
  constructor(product?: CatalogProductEntity);
12
11
  }
13
12
  declare class UpdateProductVariantRequestValidator extends UpdateVariantRequestValidator {
@@ -20,6 +19,7 @@ declare class UpdateProductVariantsItemRequestValidator extends UpdateVariantReq
20
19
  export declare class UpdateProductRequestValidator extends ProductMetadataRequestValidator {
21
20
  name: string;
22
21
  active?: boolean;
22
+ posterId?: string | null;
23
23
  variant?: UpdateProductVariantRequestValidator;
24
24
  variants?: UpdateProductVariantsItemRequestValidator[];
25
25
  constructor(product?: CatalogProductEntity);
@@ -17,7 +17,6 @@ class ProductMetadataRequestValidator extends abstract_validator_1.AbstractReque
17
17
  description;
18
18
  category;
19
19
  brand;
20
- hashtags;
21
20
  constructor(product) {
22
21
  super();
23
22
  if (!product)
@@ -26,7 +25,6 @@ class ProductMetadataRequestValidator extends abstract_validator_1.AbstractReque
26
25
  this.description = product.description;
27
26
  this.category = (product.category?._id || product.category);
28
27
  this.brand = (product.brand?._id || product.brand);
29
- this.hashtags = product.hashtags ?? [];
30
28
  }
31
29
  }
32
30
  __decorate([
@@ -52,13 +50,6 @@ __decorate([
52
50
  (0, class_validator_1.IsOptional)(),
53
51
  __metadata("design:type", String)
54
52
  ], ProductMetadataRequestValidator.prototype, "brand", void 0);
55
- __decorate([
56
- (0, class_validator_1.IsArray)(),
57
- (0, class_validator_1.IsString)({ each: true }),
58
- (0, class_validator_1.Length)(0, 50, { each: true }),
59
- (0, class_validator_1.IsOptional)(),
60
- __metadata("design:type", Array)
61
- ], ProductMetadataRequestValidator.prototype, "hashtags", void 0);
62
53
  class UpdateProductVariantRequestValidator extends request_validator_1.UpdateVariantRequestValidator {
63
54
  _id;
64
55
  constructor(variant) {
@@ -81,12 +72,15 @@ __decorate([
81
72
  ], UpdateProductVariantsItemRequestValidator.prototype, "_id", void 0);
82
73
  export class UpdateProductRequestValidator extends ProductMetadataRequestValidator {
83
74
  active;
75
+ posterId;
84
76
  variant;
85
77
  variants;
86
78
  constructor(product) {
87
79
  super(product);
88
80
  if (product)
89
81
  this.active = product.active;
82
+ if (product)
83
+ this.posterId = product.posterId ? String(product.posterId) : null;
90
84
  if (product?.variant)
91
85
  this.variant = new UpdateProductVariantRequestValidator(product.variant);
92
86
  }
@@ -100,6 +94,11 @@ __decorate([
100
94
  (0, class_validator_1.IsOptional)(),
101
95
  __metadata("design:type", Boolean)
102
96
  ], UpdateProductRequestValidator.prototype, "active", void 0);
97
+ __decorate([
98
+ (0, class_validator_1.IsMongoId)(),
99
+ (0, class_validator_1.IsOptional)(),
100
+ __metadata("design:type", String)
101
+ ], UpdateProductRequestValidator.prototype, "posterId", void 0);
103
102
  __decorate([
104
103
  (0, class_validator_1.IsOptional)(),
105
104
  (0, class_validator_1.ValidateNested)(),
@@ -1,5 +1,6 @@
1
1
  import { AbstractRequestValidator } from '../../abstract.validator.js';
2
2
  import { SaleShippingRequestValidator } from './shipping.request.validator.js';
3
+ import type { StorePaymentMethod } from '../../integration/payment';
3
4
  export declare class CheckoutItemRequestValidator extends AbstractRequestValidator {
4
5
  product: string;
5
6
  variant: string;
@@ -9,4 +10,5 @@ export declare class CreateCheckoutRequestValidator extends AbstractRequestValid
9
10
  items: CheckoutItemRequestValidator[];
10
11
  shipping: SaleShippingRequestValidator;
11
12
  notes?: string;
13
+ method?: StorePaymentMethod;
12
14
  }
@@ -10,6 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  };
11
11
  import * as class_transformer_1 from "class-transformer";
12
12
  import * as class_validator_1 from "class-validator";
13
+ import * as payment_enum_1 from '../../finance/payment/index.js';
13
14
  import * as abstract_validator_1 from '../../abstract.validator.js';
14
15
  import * as shipping_request_validator_1 from './shipping.request.validator.js';
15
16
  export class CheckoutItemRequestValidator extends abstract_validator_1.AbstractRequestValidator {
@@ -35,6 +36,7 @@ export class CreateCheckoutRequestValidator extends abstract_validator_1.Abstrac
35
36
  items = [];
36
37
  shipping = new shipping_request_validator_1.SaleShippingRequestValidator();
37
38
  notes;
39
+ method;
38
40
  }
39
41
  __decorate([
40
42
  (0, class_validator_1.IsArray)(),
@@ -56,3 +58,8 @@ __decorate([
56
58
  (0, class_validator_1.IsOptional)(),
57
59
  __metadata("design:type", String)
58
60
  ], CreateCheckoutRequestValidator.prototype, "notes", void 0);
61
+ __decorate([
62
+ (0, class_validator_1.IsIn)([payment_enum_1.FinancePaymentMethodEnum.PIX, payment_enum_1.FinancePaymentMethodEnum.CARD]),
63
+ (0, class_validator_1.IsOptional)(),
64
+ __metadata("design:type", String)
65
+ ], CreateCheckoutRequestValidator.prototype, "method", void 0);
@@ -8,7 +8,7 @@ export interface StatusEntity<TEnum extends string = string> {
8
8
  _id: Types.ObjectId;
9
9
  date: Date;
10
10
  name: TEnum;
11
- user: string;
11
+ user: string | null;
12
12
  }
13
13
  export declare function statusPlugin(schema: Schema, options: StatusPluginOptions): void;
14
14
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@merkaly/api",
3
- "version": "0.25.2",
3
+ "version": "0.26.1",
4
4
  "type": "module",
5
5
  "description": "Shared TypeScript interfaces and enums for Merkaly API",
6
6
  "repository": {
@@ -31,7 +31,7 @@
31
31
  "devDependencies": {
32
32
  "@types/node": "^26.6.1",
33
33
  "changelogen": "^0.6.2",
34
- "oxlint": "^1.89.0",
34
+ "oxlint": "^1.90.0",
35
35
  "tsx": "^4.23.0",
36
36
  "typescript": "^7.0.2"
37
37
  },