@molecule/api-resource-inventory 1.0.0
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/LICENSE +115 -0
- package/dist/authorizers/index.d.ts +133 -0
- package/dist/authorizers/index.d.ts.map +1 -0
- package/dist/authorizers/index.js +188 -0
- package/dist/browser-guard.d.ts +2 -0
- package/dist/browser-guard.d.ts.map +1 -0
- package/dist/browser-guard.js +18 -0
- package/dist/handlers/bulkUpdate.d.ts +13 -0
- package/dist/handlers/bulkUpdate.d.ts.map +1 -0
- package/dist/handlers/bulkUpdate.js +168 -0
- package/dist/handlers/confirm.d.ts +13 -0
- package/dist/handlers/confirm.d.ts.map +1 -0
- package/dist/handlers/confirm.js +68 -0
- package/dist/handlers/getAlerts.d.ts +14 -0
- package/dist/handlers/getAlerts.d.ts.map +1 -0
- package/dist/handlers/getAlerts.js +52 -0
- package/dist/handlers/getMovements.d.ts +13 -0
- package/dist/handlers/getMovements.d.ts.map +1 -0
- package/dist/handlers/getMovements.js +62 -0
- package/dist/handlers/getStock.d.ts +13 -0
- package/dist/handlers/getStock.d.ts.map +1 -0
- package/dist/handlers/getStock.js +58 -0
- package/dist/handlers/index.d.ts +9 -0
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/handlers/index.js +8 -0
- package/dist/handlers/release.d.ts +13 -0
- package/dist/handlers/release.d.ts.map +1 -0
- package/dist/handlers/release.js +67 -0
- package/dist/handlers/reserve.d.ts +13 -0
- package/dist/handlers/reserve.d.ts.map +1 -0
- package/dist/handlers/reserve.js +112 -0
- package/dist/handlers/updateStock.d.ts +13 -0
- package/dist/handlers/updateStock.d.ts.map +1 -0
- package/dist/handlers/updateStock.js +126 -0
- package/dist/i18n.d.ts +14 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +13 -0
- package/dist/index.d.ts +79 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/requestHandlerMap.d.ts +34 -0
- package/dist/requestHandlerMap.d.ts.map +1 -0
- package/dist/requestHandlerMap.js +34 -0
- package/dist/routes.d.ts +61 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/routes.js +69 -0
- package/dist/types.d.ts +234 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/utilities.d.ts +31 -0
- package/dist/utilities.d.ts.map +1 -0
- package/dist/utilities.js +79 -0
- package/package.json +54 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inventory resource types.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Types of stock adjustment operations.
|
|
8
|
+
*/
|
|
9
|
+
export type StockAdjustmentType = 'add' | 'remove' | 'set';
|
|
10
|
+
/**
|
|
11
|
+
* Types of stock movements recorded in the movement history.
|
|
12
|
+
*/
|
|
13
|
+
export type StockMovementType = 'adjustment' | 'reservation' | 'release' | 'confirmation';
|
|
14
|
+
/**
|
|
15
|
+
* Current stock information for a product or variant.
|
|
16
|
+
*/
|
|
17
|
+
export interface StockInfo {
|
|
18
|
+
/** The product this stock belongs to. */
|
|
19
|
+
productId: string;
|
|
20
|
+
/** Optional variant identifier (size, color, etc.). */
|
|
21
|
+
variantId?: string;
|
|
22
|
+
/** Quantity available for purchase (total − reserved). */
|
|
23
|
+
available: number;
|
|
24
|
+
/** Quantity currently reserved by pending orders. */
|
|
25
|
+
reserved: number;
|
|
26
|
+
/** Total quantity in stock (available + reserved). */
|
|
27
|
+
total: number;
|
|
28
|
+
/** Threshold below which the product is considered low-stock. */
|
|
29
|
+
lowStockThreshold: number;
|
|
30
|
+
/** Whether current available stock is at or below the threshold. */
|
|
31
|
+
isLowStock: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Input for adjusting stock levels.
|
|
35
|
+
*/
|
|
36
|
+
export interface StockAdjustment {
|
|
37
|
+
/** Optional variant identifier. */
|
|
38
|
+
variantId?: string;
|
|
39
|
+
/** Quantity to adjust by (or absolute value for 'set'). */
|
|
40
|
+
quantity: number;
|
|
41
|
+
/** Type of adjustment: add, remove, or set to absolute value. */
|
|
42
|
+
type: StockAdjustmentType;
|
|
43
|
+
/** Human-readable reason for the adjustment. */
|
|
44
|
+
reason?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A stock reservation tied to an order.
|
|
48
|
+
*/
|
|
49
|
+
export interface Reservation {
|
|
50
|
+
/** Unique reservation identifier. */
|
|
51
|
+
id: string;
|
|
52
|
+
/** The product being reserved. */
|
|
53
|
+
productId: string;
|
|
54
|
+
/** Optional variant identifier. */
|
|
55
|
+
variantId?: string;
|
|
56
|
+
/** Quantity reserved. */
|
|
57
|
+
quantity: number;
|
|
58
|
+
/** The order this reservation belongs to. */
|
|
59
|
+
orderId: string;
|
|
60
|
+
/** The authenticated user who created this reservation, if known. */
|
|
61
|
+
userId?: string;
|
|
62
|
+
/** When the reservation was created. */
|
|
63
|
+
createdAt: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Input for creating a stock reservation.
|
|
67
|
+
*/
|
|
68
|
+
export interface ReserveStockInput {
|
|
69
|
+
/** Quantity to reserve. */
|
|
70
|
+
quantity: number;
|
|
71
|
+
/** The order to associate this reservation with. */
|
|
72
|
+
orderId: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A low-stock alert entry.
|
|
76
|
+
*/
|
|
77
|
+
export interface LowStockAlert {
|
|
78
|
+
/** The product that is low on stock. */
|
|
79
|
+
productId: string;
|
|
80
|
+
/** Optional variant identifier. */
|
|
81
|
+
variantId?: string;
|
|
82
|
+
/** Current available quantity. */
|
|
83
|
+
available: number;
|
|
84
|
+
/** The low-stock threshold. */
|
|
85
|
+
threshold: number;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* A record of a stock movement (adjustment, reservation, release, or confirmation).
|
|
89
|
+
*/
|
|
90
|
+
export interface StockMovement {
|
|
91
|
+
/** Unique movement identifier. */
|
|
92
|
+
id: string;
|
|
93
|
+
/** The product affected. */
|
|
94
|
+
productId: string;
|
|
95
|
+
/** Optional variant identifier. */
|
|
96
|
+
variantId?: string;
|
|
97
|
+
/** Type of movement. */
|
|
98
|
+
type: StockMovementType;
|
|
99
|
+
/** Quantity change (positive for additions, negative for removals). */
|
|
100
|
+
quantity: number;
|
|
101
|
+
/** Reason or description for this movement. */
|
|
102
|
+
reason?: string;
|
|
103
|
+
/** Associated order or reservation identifier. */
|
|
104
|
+
referenceId?: string;
|
|
105
|
+
/** When this movement occurred. */
|
|
106
|
+
createdAt: string;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Pagination options for list queries.
|
|
110
|
+
*/
|
|
111
|
+
export interface PaginationOptions {
|
|
112
|
+
/** Page number (1-based). */
|
|
113
|
+
page?: number;
|
|
114
|
+
/** Number of items per page. */
|
|
115
|
+
limit?: number;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* A paginated result set.
|
|
119
|
+
*/
|
|
120
|
+
export interface PaginatedResult<T> {
|
|
121
|
+
/** The items in this page. */
|
|
122
|
+
data: T[];
|
|
123
|
+
/** Total number of items matching the query. */
|
|
124
|
+
total: number;
|
|
125
|
+
/** Current page number (1-based). */
|
|
126
|
+
page: number;
|
|
127
|
+
/** Number of items per page. */
|
|
128
|
+
limit: number;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Input for a single item in a bulk stock update.
|
|
132
|
+
*/
|
|
133
|
+
export interface BulkStockAdjustment {
|
|
134
|
+
/** The product to adjust. */
|
|
135
|
+
productId: string;
|
|
136
|
+
/** Optional variant identifier. */
|
|
137
|
+
variantId?: string;
|
|
138
|
+
/** Quantity to adjust. */
|
|
139
|
+
quantity: number;
|
|
140
|
+
/** Type of adjustment. */
|
|
141
|
+
type: StockAdjustmentType;
|
|
142
|
+
/** Reason for the adjustment. */
|
|
143
|
+
reason?: string;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Result of a single item in a bulk update.
|
|
147
|
+
*/
|
|
148
|
+
export interface BulkUpdateItemResult {
|
|
149
|
+
/** The product that was adjusted. */
|
|
150
|
+
productId: string;
|
|
151
|
+
/** Optional variant identifier. */
|
|
152
|
+
variantId?: string;
|
|
153
|
+
/** Whether this individual adjustment succeeded. */
|
|
154
|
+
success: boolean;
|
|
155
|
+
/** Error message if the adjustment failed. */
|
|
156
|
+
error?: string;
|
|
157
|
+
/** Updated stock info if successful. */
|
|
158
|
+
stock?: StockInfo;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Result of a bulk stock update operation.
|
|
162
|
+
*/
|
|
163
|
+
export interface BulkUpdateResult {
|
|
164
|
+
/** Total number of adjustments attempted. */
|
|
165
|
+
total: number;
|
|
166
|
+
/** Number of successful adjustments. */
|
|
167
|
+
succeeded: number;
|
|
168
|
+
/** Number of failed adjustments. */
|
|
169
|
+
failed: number;
|
|
170
|
+
/** Per-item results. */
|
|
171
|
+
results: BulkUpdateItemResult[];
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Internal database row for an inventory stock record.
|
|
175
|
+
*/
|
|
176
|
+
export interface StockRow {
|
|
177
|
+
/** Unique stock record identifier. */
|
|
178
|
+
id: string;
|
|
179
|
+
/** The product this stock belongs to. */
|
|
180
|
+
productId: string;
|
|
181
|
+
/** Optional variant identifier. */
|
|
182
|
+
variantId: string | null;
|
|
183
|
+
/** Total quantity in stock. */
|
|
184
|
+
total: number;
|
|
185
|
+
/** Quantity currently reserved. */
|
|
186
|
+
reserved: number;
|
|
187
|
+
/** Low-stock threshold. */
|
|
188
|
+
lowStockThreshold: number;
|
|
189
|
+
/** Creation timestamp. */
|
|
190
|
+
createdAt: string;
|
|
191
|
+
/** Last modification timestamp. */
|
|
192
|
+
updatedAt: string;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Internal database row for a stock reservation.
|
|
196
|
+
*/
|
|
197
|
+
export interface ReservationRow {
|
|
198
|
+
/** Unique reservation identifier. */
|
|
199
|
+
id: string;
|
|
200
|
+
/** The product being reserved. */
|
|
201
|
+
productId: string;
|
|
202
|
+
/** Optional variant identifier. */
|
|
203
|
+
variantId: string | null;
|
|
204
|
+
/** Quantity reserved. */
|
|
205
|
+
quantity: number;
|
|
206
|
+
/** The order this reservation belongs to. */
|
|
207
|
+
orderId: string;
|
|
208
|
+
/** The authenticated user who created this reservation (null for legacy rows). */
|
|
209
|
+
userId: string | null;
|
|
210
|
+
/** Creation timestamp. */
|
|
211
|
+
createdAt: string;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Internal database row for a stock movement.
|
|
215
|
+
*/
|
|
216
|
+
export interface StockMovementRow {
|
|
217
|
+
/** Unique movement identifier. */
|
|
218
|
+
id: string;
|
|
219
|
+
/** The product affected. */
|
|
220
|
+
productId: string;
|
|
221
|
+
/** Optional variant identifier. */
|
|
222
|
+
variantId: string | null;
|
|
223
|
+
/** Type of movement. */
|
|
224
|
+
type: StockMovementType;
|
|
225
|
+
/** Quantity change. */
|
|
226
|
+
quantity: number;
|
|
227
|
+
/** Reason for this movement. */
|
|
228
|
+
reason: string | null;
|
|
229
|
+
/** Associated reference identifier. */
|
|
230
|
+
referenceId: string | null;
|
|
231
|
+
/** Creation timestamp. */
|
|
232
|
+
createdAt: string;
|
|
233
|
+
}
|
|
234
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,KAAK,GAAG,QAAQ,GAAG,KAAK,CAAA;AAE1D;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,YAAY,GAAG,aAAa,GAAG,SAAS,GAAG,cAAc,CAAA;AAEzF;;GAEG;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A;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,kCAAkC;IAClC,EAAE,EAAE,MAAM,CAAA;IACV,4BAA4B;IAC5B,SAAS,EAAE,MAAM,CAAA;IACjB,mCAAmC;IACnC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,wBAAwB;IACxB,IAAI,EAAE,iBAAiB,CAAA;IACvB,uBAAuB;IACvB,QAAQ,EAAE,MAAM,CAAA;IAChB,gCAAgC;IAChC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,uCAAuC;IACvC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1B,0BAA0B;IAC1B,SAAS,EAAE,MAAM,CAAA;CAClB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inventory utility functions for converting database rows to typed objects.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { LowStockAlert, Reservation, ReservationRow, StockInfo, StockMovement, StockMovementRow, StockRow } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Converts a database stock row into a typed {@link StockInfo}.
|
|
9
|
+
* @param row - The raw database row.
|
|
10
|
+
* @returns The deserialized stock info.
|
|
11
|
+
*/
|
|
12
|
+
export declare function toStockInfo(row: StockRow): StockInfo;
|
|
13
|
+
/**
|
|
14
|
+
* Converts a database reservation row into a typed {@link Reservation}.
|
|
15
|
+
* @param row - The raw database row.
|
|
16
|
+
* @returns The deserialized reservation.
|
|
17
|
+
*/
|
|
18
|
+
export declare function toReservation(row: ReservationRow): Reservation;
|
|
19
|
+
/**
|
|
20
|
+
* Converts a database stock movement row into a typed {@link StockMovement}.
|
|
21
|
+
* @param row - The raw database row.
|
|
22
|
+
* @returns The deserialized stock movement.
|
|
23
|
+
*/
|
|
24
|
+
export declare function toStockMovement(row: StockMovementRow): StockMovement;
|
|
25
|
+
/**
|
|
26
|
+
* Converts a database stock row into a typed {@link LowStockAlert}.
|
|
27
|
+
* @param row - The raw database row.
|
|
28
|
+
* @returns The low-stock alert.
|
|
29
|
+
*/
|
|
30
|
+
export declare function toLowStockAlert(row: StockRow): LowStockAlert;
|
|
31
|
+
//# sourceMappingURL=utilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,cAAc,EACd,SAAS,EACT,aAAa,EACb,gBAAgB,EAChB,QAAQ,EACT,MAAM,YAAY,CAAA;AAEnB;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,QAAQ,GAAG,SAAS,CAYpD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,cAAc,GAAG,WAAW,CAW9D;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,gBAAgB,GAAG,aAAa,CAYpE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,QAAQ,GAAG,aAAa,CAQ5D"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inventory utility functions for converting database rows to typed objects.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Converts a database stock row into a typed {@link StockInfo}.
|
|
8
|
+
* @param row - The raw database row.
|
|
9
|
+
* @returns The deserialized stock info.
|
|
10
|
+
*/
|
|
11
|
+
export function toStockInfo(row) {
|
|
12
|
+
const available = row.total - row.reserved;
|
|
13
|
+
const info = {
|
|
14
|
+
productId: row.productId,
|
|
15
|
+
available,
|
|
16
|
+
reserved: row.reserved,
|
|
17
|
+
total: row.total,
|
|
18
|
+
lowStockThreshold: row.lowStockThreshold,
|
|
19
|
+
isLowStock: available <= row.lowStockThreshold,
|
|
20
|
+
};
|
|
21
|
+
if (row.variantId)
|
|
22
|
+
info.variantId = row.variantId;
|
|
23
|
+
return info;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Converts a database reservation row into a typed {@link Reservation}.
|
|
27
|
+
* @param row - The raw database row.
|
|
28
|
+
* @returns The deserialized reservation.
|
|
29
|
+
*/
|
|
30
|
+
export function toReservation(row) {
|
|
31
|
+
const reservation = {
|
|
32
|
+
id: row.id,
|
|
33
|
+
productId: row.productId,
|
|
34
|
+
quantity: row.quantity,
|
|
35
|
+
orderId: row.orderId,
|
|
36
|
+
createdAt: row.createdAt,
|
|
37
|
+
};
|
|
38
|
+
if (row.variantId)
|
|
39
|
+
reservation.variantId = row.variantId;
|
|
40
|
+
if (row.userId)
|
|
41
|
+
reservation.userId = row.userId;
|
|
42
|
+
return reservation;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Converts a database stock movement row into a typed {@link StockMovement}.
|
|
46
|
+
* @param row - The raw database row.
|
|
47
|
+
* @returns The deserialized stock movement.
|
|
48
|
+
*/
|
|
49
|
+
export function toStockMovement(row) {
|
|
50
|
+
const movement = {
|
|
51
|
+
id: row.id,
|
|
52
|
+
productId: row.productId,
|
|
53
|
+
type: row.type,
|
|
54
|
+
quantity: row.quantity,
|
|
55
|
+
createdAt: row.createdAt,
|
|
56
|
+
};
|
|
57
|
+
if (row.variantId)
|
|
58
|
+
movement.variantId = row.variantId;
|
|
59
|
+
if (row.reason)
|
|
60
|
+
movement.reason = row.reason;
|
|
61
|
+
if (row.referenceId)
|
|
62
|
+
movement.referenceId = row.referenceId;
|
|
63
|
+
return movement;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Converts a database stock row into a typed {@link LowStockAlert}.
|
|
67
|
+
* @param row - The raw database row.
|
|
68
|
+
* @returns The low-stock alert.
|
|
69
|
+
*/
|
|
70
|
+
export function toLowStockAlert(row) {
|
|
71
|
+
const alert = {
|
|
72
|
+
productId: row.productId,
|
|
73
|
+
available: row.total - row.reserved,
|
|
74
|
+
threshold: row.lowStockThreshold,
|
|
75
|
+
};
|
|
76
|
+
if (row.variantId)
|
|
77
|
+
alert.variantId = row.variantId;
|
|
78
|
+
return alert;
|
|
79
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@molecule/api-resource-inventory",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Inventory resource with stock tracking, reservations, low-stock alerts, movement history, and bulk updates.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"test": "vitest run",
|
|
11
|
+
"test:watch": "vitest"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"molecule",
|
|
24
|
+
"inventory",
|
|
25
|
+
"stock",
|
|
26
|
+
"commerce",
|
|
27
|
+
"resource"
|
|
28
|
+
],
|
|
29
|
+
"license": "Apache-2.0",
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@molecule/api-bond": "1.0.0",
|
|
32
|
+
"@molecule/api-database": "1.0.0",
|
|
33
|
+
"@molecule/api-i18n": "1.0.0",
|
|
34
|
+
"@molecule/api-logger": "1.0.0",
|
|
35
|
+
"@molecule/api-resource": "1.0.0",
|
|
36
|
+
"@types/node": "26.1.2",
|
|
37
|
+
"typescript": "6.0.3",
|
|
38
|
+
"vitest": "4.1.10"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@molecule/api-database": "^1.0.0",
|
|
42
|
+
"@molecule/api-i18n": "^1.0.0",
|
|
43
|
+
"@molecule/api-logger": "^1.0.0",
|
|
44
|
+
"@molecule/api-resource": "^1.0.0"
|
|
45
|
+
},
|
|
46
|
+
"peerDependenciesMeta": {
|
|
47
|
+
"@molecule/api-database": {
|
|
48
|
+
"optional": true
|
|
49
|
+
},
|
|
50
|
+
"@molecule/api-logger": {
|
|
51
|
+
"optional": true
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|