@merkaly/api 0.28.1 → 0.28.3

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/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # @merkaly/api
2
+
3
+ Shared contracts (types, enums, validators and transitions) of the Merkaly API, published to npm
4
+ and used by the frontends (admin, store, dashboard). The source of truth is
5
+ `apps/api.merkaly.io`: nothing here is written by hand except `manifest.json`.
6
+
7
+ ## How it is built
8
+
9
+ 1. `pnpm build` in `apps/api.merkaly.io` produces its `dist/`.
10
+ 2. `pnpm sync` here copies the `.d.ts`/`.js` files listed in `manifest.json` from that `dist/` into
11
+ `src/`, rewriting imports between them.
12
+ 3. `pnpm build` here (`build.ts`) generates `dist/` with one barrel per entry point.
13
+
14
+ ### `manifest.json`
15
+
16
+ - `paths` maps each public entry point to the api files it exports (relative to `api/dist/src`).
17
+ - **A leaf that is an array becomes an entry point with a barrel**: `"@/order": { "sale": [...] }`
18
+ is importable as `@merkaly/api/order/sale`. Intermediate maps do not generate one, so
19
+ `@merkaly/api/order` alone does not resolve: add a leaf (`type`, `home`...) instead.
20
+ - New domains need their group here (e.g. `"@/dashboard": { "home": [...] }`) or their types
21
+ never reach the package.
22
+
23
+ ### After `pnpm sync`
24
+
25
+ TypeScript emits `from "x"` with double quotes; the committed files use single quotes. Normalize
26
+ only the `from` clauses (inline `import("mongoose")` types keep double quotes):
27
+
28
+ ```bash
29
+ find src -name '*.d.ts' -exec perl -pi -e 's/(\bfrom )"([^"]+)"/$1\x27$2\x27/g' {} +
30
+ ```
31
+
32
+ If `git status` then shows files you did not mean to change, the api has unsynced changes: review
33
+ them before committing.
34
+
35
+ ## Testing in a frontend before publishing
36
+
37
+ ```bash
38
+ rm node_modules/@merkaly/api
39
+ ln -s ../../../../packages/api node_modules/@merkaly/api # from the app folder
40
+ rm -rf node_modules/.cache/vite # then restart its dev server
41
+ ```
42
+
43
+ Restore with `pnpm add @merkaly/api@<version>` once published. Frontends always use the
44
+ published package, never local types.
45
+
46
+ ## Release
47
+
48
+ 1. Merge the contracts PR (after the api PR it depends on).
49
+ 2. On `master`: bump `version` in `package.json` and commit `chore: release @merkaly/api vX.Y.Z`.
50
+ 3. Push the tag `vX.Y.Z`: `release.yml` typechecks, lints, builds and publishes to npm. The tag
51
+ must match `package.json`.
52
+ 4. Bump the dependency in each frontend (`chore(deps): bump @merkaly/api to X.Y.Z`).
53
+
54
+ **Versioning**: patch by default (new contracts, fields or fixes); minor only when something a
55
+ frontend uses is removed or changes shape.
@@ -0,0 +1,47 @@
1
+ import type { PaymentAccountBalance, PaymentAccountStatus } from '../../integration/payment';
2
+ import type { SupplierConnectionStatus } from '../../integration/supplier';
3
+ import type { OrderSaleAttentionEnum } from '../../order/sale';
4
+ import type { OrderSaleStatusEnum } from '../../order/sale';
5
+ import type { OrderSaleAttentionSummary } from '../../order/sale';
6
+ export interface DashboardHomeDay {
7
+ date: string;
8
+ orders: number;
9
+ revenue: number;
10
+ }
11
+ export interface DashboardHomePeriod {
12
+ days: number;
13
+ from: Date;
14
+ to: Date;
15
+ orders: number;
16
+ revenue: number;
17
+ profit: number;
18
+ margin: number | null;
19
+ withoutCost: number;
20
+ series: DashboardHomeDay[];
21
+ }
22
+ export interface DashboardHomeSale {
23
+ _id: string;
24
+ number: string;
25
+ createdAt: Date;
26
+ customer: string | null;
27
+ total: number;
28
+ profit: number | null;
29
+ status: OrderSaleStatusEnum;
30
+ attention: OrderSaleAttentionEnum | null;
31
+ }
32
+ export interface DashboardHomeIntegrations {
33
+ supplier: SupplierConnectionStatus | null;
34
+ payment: PaymentAccountStatus | null;
35
+ balance: PaymentAccountBalance | null;
36
+ failures: ('supplier' | 'payment' | 'balance')[];
37
+ }
38
+ export interface DashboardHomeOnboarding {
39
+ products: number;
40
+ sales: number;
41
+ }
42
+ export interface DashboardHome {
43
+ attention: OrderSaleAttentionSummary;
44
+ recent: DashboardHomeSale[];
45
+ integrations: DashboardHomeIntegrations;
46
+ onboarding: DashboardHomeOnboarding;
47
+ }
@@ -0,0 +1,2 @@
1
+ export * from './home';
2
+ export * from './period.request.validator';
@@ -0,0 +1 @@
1
+ export * from './period.request.validator.js';
@@ -0,0 +1,5 @@
1
+ import { AbstractRequestValidator } from '../../abstract.validator.js';
2
+ export declare const DASHBOARD_PERIOD_DAYS: readonly [7, 30, 90];
3
+ export declare class DashboardPeriodRequestValidator extends AbstractRequestValidator {
4
+ days?: (typeof DASHBOARD_PERIOD_DAYS)[number];
5
+ }
@@ -0,0 +1,23 @@
1
+ import 'reflect-metadata';
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ import * as class_transformer_1 from "class-transformer";
12
+ import * as class_validator_1 from "class-validator";
13
+ import * as abstract_validator_1 from '../../abstract.validator.js';
14
+ export const DASHBOARD_PERIOD_DAYS = [7, 30, 90];
15
+ export class DashboardPeriodRequestValidator extends abstract_validator_1.AbstractRequestValidator {
16
+ days = 30;
17
+ }
18
+ __decorate([
19
+ (0, class_validator_1.IsIn)(DASHBOARD_PERIOD_DAYS),
20
+ (0, class_validator_1.IsOptional)(),
21
+ (0, class_transformer_1.Type)(() => Number),
22
+ __metadata("design:type", Object)
23
+ ], DashboardPeriodRequestValidator.prototype, "days", void 0);
package/dist/index.d.ts CHANGED
@@ -15,6 +15,7 @@ export * from './account/user';
15
15
  export * from './assets/asset';
16
16
  export * from './contact/customer';
17
17
  export * from './contact/vendor';
18
+ export * from './dashboard/home';
18
19
  export * from './finance/payment';
19
20
  export * from './integration/supplier';
20
21
  export * from './integration/payment';
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ export * from './account/user/index.js';
7
7
  export * from './assets/asset/index.js';
8
8
  export * from './contact/customer/index.js';
9
9
  export * from './contact/vendor/index.js';
10
+ export * from './dashboard/home/index.js';
10
11
  export * from './finance/payment/index.js';
11
12
  export * from './integration/supplier/index.js';
12
13
  export * from './integration/payment/index.js';
@@ -1,9 +1,12 @@
1
1
  import { AbstractEntity } from '../../../abstract.entity.js';
2
2
  import { CatalogRelationStatusEnum } from '../../../relation.status.enum.js';
3
3
  import { CatalogProductEntity } from '../product';
4
+ import type { AssetEntity } from '../../../assets/asset';
4
5
  export declare class CatalogBrandEntity extends AbstractEntity {
5
6
  name: string;
6
7
  description: string;
8
+ posterId?: string | null;
9
+ readonly poster?: AssetEntity | null;
7
10
  readonly products?: CatalogProductEntity[];
8
11
  readonly status: CatalogRelationStatusEnum;
9
12
  }
@@ -3,6 +3,7 @@ import type { CatalogBrandEntity } from './brand.entity.js';
3
3
  export declare class CreateBrandRequestValidator extends AbstractRequestValidator {
4
4
  name: string;
5
5
  description?: string;
6
+ posterId?: string | null;
6
7
  constructor(brand?: CatalogBrandEntity);
7
8
  }
8
9
  export declare class UpdateBrandRequestValidator extends CreateBrandRequestValidator {
@@ -13,6 +13,7 @@ import * as abstract_validator_1 from '../../../abstract.validator.js';
13
13
  export class CreateBrandRequestValidator extends abstract_validator_1.AbstractRequestValidator {
14
14
  name;
15
15
  description;
16
+ posterId;
16
17
  constructor(brand) {
17
18
  super();
18
19
  if (!brand) {
@@ -20,6 +21,7 @@ export class CreateBrandRequestValidator extends abstract_validator_1.AbstractRe
20
21
  }
21
22
  this.name = brand.name;
22
23
  this.description = brand.description;
24
+ this.posterId = brand.posterId ? String(brand.posterId) : null;
23
25
  }
24
26
  }
25
27
  __decorate([
@@ -34,6 +36,11 @@ __decorate([
34
36
  (0, class_validator_1.IsOptional)(),
35
37
  __metadata("design:type", String)
36
38
  ], CreateBrandRequestValidator.prototype, "description", void 0);
39
+ __decorate([
40
+ (0, class_validator_1.IsMongoId)(),
41
+ (0, class_validator_1.IsOptional)(),
42
+ __metadata("design:type", String)
43
+ ], CreateBrandRequestValidator.prototype, "posterId", void 0);
37
44
  export class UpdateBrandRequestValidator extends CreateBrandRequestValidator {
38
45
  }
39
46
  __decorate([
@@ -1,11 +1,14 @@
1
1
  import { AbstractEntity } from '../../../abstract.entity.js';
2
2
  import { CatalogRelationStatusEnum } from '../../../relation.status.enum.js';
3
3
  import { CatalogProductEntity } from '../product';
4
+ import type { AssetEntity } from '../../../assets/asset';
4
5
  export declare class CatalogCategoryEntity extends AbstractEntity {
5
6
  name: string;
6
7
  description?: string;
7
8
  icon?: string | null;
8
9
  parent?: CatalogCategoryEntity;
10
+ posterId?: string | null;
11
+ readonly poster?: AssetEntity | null;
9
12
  readonly children?: CatalogCategoryEntity[];
10
13
  readonly products?: CatalogProductEntity[];
11
14
  readonly status: CatalogRelationStatusEnum;
@@ -5,6 +5,7 @@ export declare class CreateCategoryRequestValidator extends AbstractRequestValid
5
5
  description?: string;
6
6
  icon?: string | null;
7
7
  parent?: string | null;
8
+ posterId?: string | null;
8
9
  constructor(category?: CatalogCategoryEntity);
9
10
  }
10
11
  export declare class UpdateCategoryRequestValidator extends CreateCategoryRequestValidator {
@@ -15,6 +15,7 @@ export class CreateCategoryRequestValidator extends abstract_validator_1.Abstrac
15
15
  description;
16
16
  icon;
17
17
  parent;
18
+ posterId;
18
19
  constructor(category) {
19
20
  super();
20
21
  if (!category) {
@@ -24,6 +25,7 @@ export class CreateCategoryRequestValidator extends abstract_validator_1.Abstrac
24
25
  this.description = category.description;
25
26
  this.icon = category.icon;
26
27
  this.parent = category.parent ? String(category.parent._id ?? category.parent) : null;
28
+ this.posterId = category.posterId ? String(category.posterId) : null;
27
29
  }
28
30
  }
29
31
  __decorate([
@@ -50,6 +52,11 @@ __decorate([
50
52
  (0, class_validator_1.IsOptional)(),
51
53
  __metadata("design:type", String)
52
54
  ], CreateCategoryRequestValidator.prototype, "parent", void 0);
55
+ __decorate([
56
+ (0, class_validator_1.IsMongoId)(),
57
+ (0, class_validator_1.IsOptional)(),
58
+ __metadata("design:type", String)
59
+ ], CreateCategoryRequestValidator.prototype, "posterId", void 0);
53
60
  export class UpdateCategoryRequestValidator extends CreateCategoryRequestValidator {
54
61
  }
55
62
  __decorate([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@merkaly/api",
3
- "version": "0.28.1",
3
+ "version": "0.28.3",
4
4
  "type": "module",
5
5
  "description": "Shared TypeScript interfaces and enums for Merkaly API",
6
6
  "repository": {