@voyantjs/markets 0.2.0 → 0.3.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.
@@ -0,0 +1,253 @@
1
+ import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
2
+ import type { CreateExchangeRateInput, CreateFxRateSetInput, CreateMarketCurrencyInput, CreateMarketInput, CreateMarketLocaleInput, ExchangeRateListQuery, FxRateSetListQuery, MarketCurrencyListQuery, MarketListQuery, MarketLocaleListQuery, UpdateExchangeRateInput, UpdateFxRateSetInput, UpdateMarketCurrencyInput, UpdateMarketInput, UpdateMarketLocaleInput } from "./service-shared.js";
3
+ export declare function listMarkets(db: PostgresJsDatabase, query: MarketListQuery): Promise<{
4
+ data: {
5
+ id: string;
6
+ code: string;
7
+ name: string;
8
+ status: "active" | "inactive" | "archived";
9
+ regionCode: string | null;
10
+ countryCode: string | null;
11
+ defaultLanguageTag: string;
12
+ defaultCurrency: string;
13
+ timezone: string | null;
14
+ taxContext: string | null;
15
+ metadata: Record<string, unknown> | null;
16
+ createdAt: Date;
17
+ updatedAt: Date;
18
+ }[];
19
+ total: number;
20
+ limit: number;
21
+ offset: number;
22
+ }>;
23
+ export declare function getMarketById(db: PostgresJsDatabase, id: string): Promise<{
24
+ id: string;
25
+ code: string;
26
+ name: string;
27
+ status: "active" | "inactive" | "archived";
28
+ regionCode: string | null;
29
+ countryCode: string | null;
30
+ defaultLanguageTag: string;
31
+ defaultCurrency: string;
32
+ timezone: string | null;
33
+ taxContext: string | null;
34
+ metadata: Record<string, unknown> | null;
35
+ createdAt: Date;
36
+ updatedAt: Date;
37
+ } | null>;
38
+ export declare function createMarket(db: PostgresJsDatabase, data: CreateMarketInput): Promise<{
39
+ id: string;
40
+ name: string;
41
+ code: string;
42
+ status: "active" | "inactive" | "archived";
43
+ regionCode: string | null;
44
+ countryCode: string | null;
45
+ defaultLanguageTag: string;
46
+ defaultCurrency: string;
47
+ timezone: string | null;
48
+ taxContext: string | null;
49
+ metadata: Record<string, unknown> | null;
50
+ createdAt: Date;
51
+ updatedAt: Date;
52
+ } | null>;
53
+ export declare function updateMarket(db: PostgresJsDatabase, id: string, data: UpdateMarketInput): Promise<{
54
+ id: string;
55
+ code: string;
56
+ name: string;
57
+ status: "active" | "inactive" | "archived";
58
+ regionCode: string | null;
59
+ countryCode: string | null;
60
+ defaultLanguageTag: string;
61
+ defaultCurrency: string;
62
+ timezone: string | null;
63
+ taxContext: string | null;
64
+ metadata: Record<string, unknown> | null;
65
+ createdAt: Date;
66
+ updatedAt: Date;
67
+ } | null>;
68
+ export declare function deleteMarket(db: PostgresJsDatabase, id: string): Promise<{
69
+ id: string;
70
+ } | null>;
71
+ export declare function listMarketLocales(db: PostgresJsDatabase, query: MarketLocaleListQuery): Promise<{
72
+ data: {
73
+ id: string;
74
+ marketId: string;
75
+ languageTag: string;
76
+ isDefault: boolean;
77
+ sortOrder: number;
78
+ active: boolean;
79
+ createdAt: Date;
80
+ updatedAt: Date;
81
+ }[];
82
+ total: number;
83
+ limit: number;
84
+ offset: number;
85
+ }>;
86
+ export declare function createMarketLocale(db: PostgresJsDatabase, marketId: string, data: CreateMarketLocaleInput): Promise<{
87
+ id: string;
88
+ active: boolean;
89
+ createdAt: Date;
90
+ updatedAt: Date;
91
+ marketId: string;
92
+ languageTag: string;
93
+ isDefault: boolean;
94
+ sortOrder: number;
95
+ } | null>;
96
+ export declare function updateMarketLocale(db: PostgresJsDatabase, id: string, data: UpdateMarketLocaleInput): Promise<{
97
+ id: string;
98
+ marketId: string;
99
+ languageTag: string;
100
+ isDefault: boolean;
101
+ sortOrder: number;
102
+ active: boolean;
103
+ createdAt: Date;
104
+ updatedAt: Date;
105
+ } | null>;
106
+ export declare function deleteMarketLocale(db: PostgresJsDatabase, id: string): Promise<{
107
+ id: string;
108
+ } | null>;
109
+ export declare function listMarketCurrencies(db: PostgresJsDatabase, query: MarketCurrencyListQuery): Promise<{
110
+ data: {
111
+ id: string;
112
+ marketId: string;
113
+ currencyCode: string;
114
+ isDefault: boolean;
115
+ isSettlement: boolean;
116
+ isReporting: boolean;
117
+ sortOrder: number;
118
+ active: boolean;
119
+ createdAt: Date;
120
+ updatedAt: Date;
121
+ }[];
122
+ total: number;
123
+ limit: number;
124
+ offset: number;
125
+ }>;
126
+ export declare function createMarketCurrency(db: PostgresJsDatabase, marketId: string, data: CreateMarketCurrencyInput): Promise<{
127
+ id: string;
128
+ active: boolean;
129
+ createdAt: Date;
130
+ updatedAt: Date;
131
+ marketId: string;
132
+ isDefault: boolean;
133
+ sortOrder: number;
134
+ currencyCode: string;
135
+ isSettlement: boolean;
136
+ isReporting: boolean;
137
+ } | null>;
138
+ export declare function updateMarketCurrency(db: PostgresJsDatabase, id: string, data: UpdateMarketCurrencyInput): Promise<{
139
+ id: string;
140
+ marketId: string;
141
+ currencyCode: string;
142
+ isDefault: boolean;
143
+ isSettlement: boolean;
144
+ isReporting: boolean;
145
+ sortOrder: number;
146
+ active: boolean;
147
+ createdAt: Date;
148
+ updatedAt: Date;
149
+ } | null>;
150
+ export declare function deleteMarketCurrency(db: PostgresJsDatabase, id: string): Promise<{
151
+ id: string;
152
+ } | null>;
153
+ export declare function listFxRateSets(db: PostgresJsDatabase, query: FxRateSetListQuery): Promise<{
154
+ data: {
155
+ id: string;
156
+ source: "supplier" | "manual" | "ecb" | "custom" | "channel" | "other";
157
+ baseCurrency: string;
158
+ effectiveAt: Date;
159
+ observedAt: Date | null;
160
+ sourceReference: string | null;
161
+ notes: string | null;
162
+ metadata: Record<string, unknown> | null;
163
+ createdAt: Date;
164
+ }[];
165
+ total: number;
166
+ limit: number;
167
+ offset: number;
168
+ }>;
169
+ export declare function getFxRateSetById(db: PostgresJsDatabase, id: string): Promise<{
170
+ id: string;
171
+ source: "supplier" | "manual" | "ecb" | "custom" | "channel" | "other";
172
+ baseCurrency: string;
173
+ effectiveAt: Date;
174
+ observedAt: Date | null;
175
+ sourceReference: string | null;
176
+ notes: string | null;
177
+ metadata: Record<string, unknown> | null;
178
+ createdAt: Date;
179
+ } | null>;
180
+ export declare function createFxRateSet(db: PostgresJsDatabase, data: CreateFxRateSetInput): Promise<{
181
+ id: string;
182
+ metadata: Record<string, unknown> | null;
183
+ createdAt: Date;
184
+ source: "supplier" | "manual" | "ecb" | "custom" | "channel" | "other";
185
+ baseCurrency: string;
186
+ effectiveAt: Date;
187
+ observedAt: Date | null;
188
+ sourceReference: string | null;
189
+ notes: string | null;
190
+ } | null>;
191
+ export declare function updateFxRateSet(db: PostgresJsDatabase, id: string, data: UpdateFxRateSetInput): Promise<{
192
+ id: string;
193
+ source: "supplier" | "manual" | "ecb" | "custom" | "channel" | "other";
194
+ baseCurrency: string;
195
+ effectiveAt: Date;
196
+ observedAt: Date | null;
197
+ sourceReference: string | null;
198
+ notes: string | null;
199
+ metadata: Record<string, unknown> | null;
200
+ createdAt: Date;
201
+ } | null>;
202
+ export declare function deleteFxRateSet(db: PostgresJsDatabase, id: string): Promise<{
203
+ id: string;
204
+ } | null>;
205
+ export declare function listExchangeRates(db: PostgresJsDatabase, query: ExchangeRateListQuery): Promise<{
206
+ data: {
207
+ id: string;
208
+ fxRateSetId: string;
209
+ baseCurrency: string;
210
+ quoteCurrency: string;
211
+ rateDecimal: string;
212
+ inverseRateDecimal: string | null;
213
+ observedAt: Date | null;
214
+ createdAt: Date;
215
+ }[];
216
+ total: number;
217
+ limit: number;
218
+ offset: number;
219
+ }>;
220
+ export declare function getExchangeRateById(db: PostgresJsDatabase, id: string): Promise<{
221
+ id: string;
222
+ fxRateSetId: string;
223
+ baseCurrency: string;
224
+ quoteCurrency: string;
225
+ rateDecimal: string;
226
+ inverseRateDecimal: string | null;
227
+ observedAt: Date | null;
228
+ createdAt: Date;
229
+ } | null>;
230
+ export declare function createExchangeRate(db: PostgresJsDatabase, fxRateSetId: string, data: CreateExchangeRateInput): Promise<{
231
+ id: string;
232
+ createdAt: Date;
233
+ baseCurrency: string;
234
+ observedAt: Date | null;
235
+ fxRateSetId: string;
236
+ quoteCurrency: string;
237
+ rateDecimal: string;
238
+ inverseRateDecimal: string | null;
239
+ } | null>;
240
+ export declare function updateExchangeRate(db: PostgresJsDatabase, id: string, data: UpdateExchangeRateInput): Promise<{
241
+ id: string;
242
+ fxRateSetId: string;
243
+ baseCurrency: string;
244
+ quoteCurrency: string;
245
+ rateDecimal: string;
246
+ inverseRateDecimal: string | null;
247
+ observedAt: Date | null;
248
+ createdAt: Date;
249
+ } | null>;
250
+ export declare function deleteExchangeRate(db: PostgresJsDatabase, id: string): Promise<{
251
+ id: string;
252
+ } | null>;
253
+ //# sourceMappingURL=service-core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-core.d.ts","sourceRoot":"","sources":["../src/service-core.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAGjE,OAAO,KAAK,EACV,uBAAuB,EACvB,oBAAoB,EACpB,yBAAyB,EACzB,iBAAiB,EACjB,uBAAuB,EACvB,qBAAqB,EACrB,kBAAkB,EAClB,uBAAuB,EACvB,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,yBAAyB,EACzB,iBAAiB,EACjB,uBAAuB,EACxB,MAAM,qBAAqB,CAAA;AAG5B,wBAAsB,WAAW,CAAC,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,eAAe;;;;;;;;;;;;;;;;;;;GAqB/E;AAED,wBAAsB,aAAa,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;;;;;;;;;;;;;UAGrE;AAED,wBAAsB,YAAY,CAAC,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,iBAAiB;;;;;;;;;;;;;;UAGjF;AAED,wBAAsB,YAAY,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB;;;;;;;;;;;;;;UAO7F;AAED,wBAAsB,YAAY,CAAC,EAA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AI,EAAE,oBAAoB;;;;;;;;;;UAa3B;AAED,wBAAsB,eAAe,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;UAMvE;AAED,wBAAsB,iBAAiB,CAAC,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,qBAAqB;;;;;;;;;;;;;;GAkB3F;AAED,wBAAsB,mBAAmB,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;;;;;;;;UAG3E;AAED,wBAAsB,kBAAkB,CACtC,EAAE,EAAE,kBAAkB,EACtB,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,uBAAuB;;;;;;;;;UAkB9B;AAED,wBAAsB,kBAAkB,CACtC,EAAE,EAAE,kBAAkB,EACtB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,uBAAuB;;;;;;;;;UAY9B;AAED,wBAAsB,kBAAkB,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;UAM1E"}
@@ -0,0 +1,242 @@
1
+ import { and, asc, desc, eq, ilike, or, sql } from "drizzle-orm";
2
+ import { exchangeRates, fxRateSets, marketCurrencies, marketLocales, markets } from "./schema.js";
3
+ import { paginate, toTimestamp } from "./service-shared.js";
4
+ export async function listMarkets(db, query) {
5
+ const conditions = [];
6
+ if (query.status)
7
+ conditions.push(eq(markets.status, query.status));
8
+ if (query.countryCode)
9
+ conditions.push(eq(markets.countryCode, query.countryCode));
10
+ if (query.search) {
11
+ const term = `%${query.search}%`;
12
+ conditions.push(or(ilike(markets.name, term), ilike(markets.code, term)));
13
+ }
14
+ const where = conditions.length > 0 ? and(...conditions) : undefined;
15
+ return paginate(db
16
+ .select()
17
+ .from(markets)
18
+ .where(where)
19
+ .limit(query.limit)
20
+ .offset(query.offset)
21
+ .orderBy(desc(markets.updatedAt)), db.select({ count: sql `count(*)::int` }).from(markets).where(where), query.limit, query.offset);
22
+ }
23
+ export async function getMarketById(db, id) {
24
+ const [row] = await db.select().from(markets).where(eq(markets.id, id)).limit(1);
25
+ return row ?? null;
26
+ }
27
+ export async function createMarket(db, data) {
28
+ const [row] = await db.insert(markets).values(data).returning();
29
+ return row ?? null;
30
+ }
31
+ export async function updateMarket(db, id, data) {
32
+ const [row] = await db
33
+ .update(markets)
34
+ .set({ ...data, updatedAt: new Date() })
35
+ .where(eq(markets.id, id))
36
+ .returning();
37
+ return row ?? null;
38
+ }
39
+ export async function deleteMarket(db, id) {
40
+ const [row] = await db.delete(markets).where(eq(markets.id, id)).returning({ id: markets.id });
41
+ return row ?? null;
42
+ }
43
+ export async function listMarketLocales(db, query) {
44
+ const conditions = [];
45
+ if (query.marketId)
46
+ conditions.push(eq(marketLocales.marketId, query.marketId));
47
+ if (query.languageTag)
48
+ conditions.push(eq(marketLocales.languageTag, query.languageTag));
49
+ if (query.active !== undefined)
50
+ conditions.push(eq(marketLocales.active, query.active));
51
+ const where = conditions.length > 0 ? and(...conditions) : undefined;
52
+ return paginate(db
53
+ .select()
54
+ .from(marketLocales)
55
+ .where(where)
56
+ .limit(query.limit)
57
+ .offset(query.offset)
58
+ .orderBy(asc(marketLocales.sortOrder), asc(marketLocales.createdAt)), db.select({ count: sql `count(*)::int` }).from(marketLocales).where(where), query.limit, query.offset);
59
+ }
60
+ export async function createMarketLocale(db, marketId, data) {
61
+ const [market] = await db
62
+ .select({ id: markets.id })
63
+ .from(markets)
64
+ .where(eq(markets.id, marketId))
65
+ .limit(1);
66
+ if (!market)
67
+ return null;
68
+ const [row] = await db
69
+ .insert(marketLocales)
70
+ .values({ ...data, marketId })
71
+ .returning();
72
+ return row ?? null;
73
+ }
74
+ export async function updateMarketLocale(db, id, data) {
75
+ const [row] = await db
76
+ .update(marketLocales)
77
+ .set({ ...data, updatedAt: new Date() })
78
+ .where(eq(marketLocales.id, id))
79
+ .returning();
80
+ return row ?? null;
81
+ }
82
+ export async function deleteMarketLocale(db, id) {
83
+ const [row] = await db
84
+ .delete(marketLocales)
85
+ .where(eq(marketLocales.id, id))
86
+ .returning({ id: marketLocales.id });
87
+ return row ?? null;
88
+ }
89
+ export async function listMarketCurrencies(db, query) {
90
+ const conditions = [];
91
+ if (query.marketId)
92
+ conditions.push(eq(marketCurrencies.marketId, query.marketId));
93
+ if (query.currencyCode)
94
+ conditions.push(eq(marketCurrencies.currencyCode, query.currencyCode));
95
+ if (query.active !== undefined)
96
+ conditions.push(eq(marketCurrencies.active, query.active));
97
+ const where = conditions.length > 0 ? and(...conditions) : undefined;
98
+ return paginate(db
99
+ .select()
100
+ .from(marketCurrencies)
101
+ .where(where)
102
+ .limit(query.limit)
103
+ .offset(query.offset)
104
+ .orderBy(asc(marketCurrencies.sortOrder), asc(marketCurrencies.createdAt)), db.select({ count: sql `count(*)::int` }).from(marketCurrencies).where(where), query.limit, query.offset);
105
+ }
106
+ export async function createMarketCurrency(db, marketId, data) {
107
+ const [market] = await db
108
+ .select({ id: markets.id })
109
+ .from(markets)
110
+ .where(eq(markets.id, marketId))
111
+ .limit(1);
112
+ if (!market)
113
+ return null;
114
+ const [row] = await db
115
+ .insert(marketCurrencies)
116
+ .values({ ...data, marketId })
117
+ .returning();
118
+ return row ?? null;
119
+ }
120
+ export async function updateMarketCurrency(db, id, data) {
121
+ const [row] = await db
122
+ .update(marketCurrencies)
123
+ .set({ ...data, updatedAt: new Date() })
124
+ .where(eq(marketCurrencies.id, id))
125
+ .returning();
126
+ return row ?? null;
127
+ }
128
+ export async function deleteMarketCurrency(db, id) {
129
+ const [row] = await db
130
+ .delete(marketCurrencies)
131
+ .where(eq(marketCurrencies.id, id))
132
+ .returning({ id: marketCurrencies.id });
133
+ return row ?? null;
134
+ }
135
+ export async function listFxRateSets(db, query) {
136
+ const conditions = [];
137
+ if (query.source)
138
+ conditions.push(eq(fxRateSets.source, query.source));
139
+ if (query.baseCurrency)
140
+ conditions.push(eq(fxRateSets.baseCurrency, query.baseCurrency));
141
+ const where = conditions.length > 0 ? and(...conditions) : undefined;
142
+ return paginate(db
143
+ .select()
144
+ .from(fxRateSets)
145
+ .where(where)
146
+ .limit(query.limit)
147
+ .offset(query.offset)
148
+ .orderBy(desc(fxRateSets.effectiveAt)), db.select({ count: sql `count(*)::int` }).from(fxRateSets).where(where), query.limit, query.offset);
149
+ }
150
+ export async function getFxRateSetById(db, id) {
151
+ const [row] = await db.select().from(fxRateSets).where(eq(fxRateSets.id, id)).limit(1);
152
+ return row ?? null;
153
+ }
154
+ export async function createFxRateSet(db, data) {
155
+ const [row] = await db
156
+ .insert(fxRateSets)
157
+ .values({
158
+ ...data,
159
+ effectiveAt: toTimestamp(data.effectiveAt) ?? new Date(),
160
+ observedAt: toTimestamp(data.observedAt),
161
+ })
162
+ .returning();
163
+ return row ?? null;
164
+ }
165
+ export async function updateFxRateSet(db, id, data) {
166
+ const { effectiveAt, observedAt, ...rest } = data;
167
+ const [row] = await db
168
+ .update(fxRateSets)
169
+ .set({
170
+ ...rest,
171
+ effectiveAt: effectiveAt === undefined ? undefined : (toTimestamp(effectiveAt) ?? new Date()),
172
+ observedAt: observedAt === undefined ? undefined : toTimestamp(observedAt),
173
+ })
174
+ .where(eq(fxRateSets.id, id))
175
+ .returning();
176
+ return row ?? null;
177
+ }
178
+ export async function deleteFxRateSet(db, id) {
179
+ const [row] = await db
180
+ .delete(fxRateSets)
181
+ .where(eq(fxRateSets.id, id))
182
+ .returning({ id: fxRateSets.id });
183
+ return row ?? null;
184
+ }
185
+ export async function listExchangeRates(db, query) {
186
+ const conditions = [];
187
+ if (query.fxRateSetId)
188
+ conditions.push(eq(exchangeRates.fxRateSetId, query.fxRateSetId));
189
+ if (query.baseCurrency)
190
+ conditions.push(eq(exchangeRates.baseCurrency, query.baseCurrency));
191
+ if (query.quoteCurrency)
192
+ conditions.push(eq(exchangeRates.quoteCurrency, query.quoteCurrency));
193
+ const where = conditions.length > 0 ? and(...conditions) : undefined;
194
+ return paginate(db
195
+ .select()
196
+ .from(exchangeRates)
197
+ .where(where)
198
+ .limit(query.limit)
199
+ .offset(query.offset)
200
+ .orderBy(asc(exchangeRates.createdAt)), db.select({ count: sql `count(*)::int` }).from(exchangeRates).where(where), query.limit, query.offset);
201
+ }
202
+ export async function getExchangeRateById(db, id) {
203
+ const [row] = await db.select().from(exchangeRates).where(eq(exchangeRates.id, id)).limit(1);
204
+ return row ?? null;
205
+ }
206
+ export async function createExchangeRate(db, fxRateSetId, data) {
207
+ const [rateSet] = await db
208
+ .select({ id: fxRateSets.id })
209
+ .from(fxRateSets)
210
+ .where(eq(fxRateSets.id, fxRateSetId))
211
+ .limit(1);
212
+ if (!rateSet)
213
+ return null;
214
+ const [row] = await db
215
+ .insert(exchangeRates)
216
+ .values({
217
+ ...data,
218
+ fxRateSetId,
219
+ observedAt: toTimestamp(data.observedAt),
220
+ })
221
+ .returning();
222
+ return row ?? null;
223
+ }
224
+ export async function updateExchangeRate(db, id, data) {
225
+ const { observedAt, ...rest } = data;
226
+ const [row] = await db
227
+ .update(exchangeRates)
228
+ .set({
229
+ ...rest,
230
+ observedAt: observedAt === undefined ? undefined : toTimestamp(observedAt),
231
+ })
232
+ .where(eq(exchangeRates.id, id))
233
+ .returning();
234
+ return row ?? null;
235
+ }
236
+ export async function deleteExchangeRate(db, id) {
237
+ const [row] = await db
238
+ .delete(exchangeRates)
239
+ .where(eq(exchangeRates.id, id))
240
+ .returning({ id: exchangeRates.id });
241
+ return row ?? null;
242
+ }
@@ -0,0 +1,191 @@
1
+ import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
2
+ import type { CreateMarketChannelRuleInput, CreateMarketPriceCatalogInput, CreateMarketProductRuleInput, MarketChannelRuleListQuery, MarketPriceCatalogListQuery, MarketProductRuleListQuery, UpdateMarketChannelRuleInput, UpdateMarketPriceCatalogInput, UpdateMarketProductRuleInput } from "./service-shared.js";
3
+ export declare function listMarketPriceCatalogs(db: PostgresJsDatabase, query: MarketPriceCatalogListQuery): Promise<{
4
+ data: {
5
+ id: string;
6
+ marketId: string;
7
+ priceCatalogId: string;
8
+ isDefault: boolean;
9
+ priority: number;
10
+ active: boolean;
11
+ notes: string | null;
12
+ metadata: Record<string, unknown> | null;
13
+ createdAt: Date;
14
+ updatedAt: Date;
15
+ }[];
16
+ total: number;
17
+ limit: number;
18
+ offset: number;
19
+ }>;
20
+ export declare function getMarketPriceCatalogById(db: PostgresJsDatabase, id: string): Promise<{
21
+ id: string;
22
+ marketId: string;
23
+ priceCatalogId: string;
24
+ isDefault: boolean;
25
+ priority: number;
26
+ active: boolean;
27
+ notes: string | null;
28
+ metadata: Record<string, unknown> | null;
29
+ createdAt: Date;
30
+ updatedAt: Date;
31
+ } | null>;
32
+ export declare function createMarketPriceCatalog(db: PostgresJsDatabase, data: CreateMarketPriceCatalogInput): Promise<{
33
+ id: string;
34
+ active: boolean;
35
+ metadata: Record<string, unknown> | null;
36
+ createdAt: Date;
37
+ updatedAt: Date;
38
+ marketId: string;
39
+ isDefault: boolean;
40
+ notes: string | null;
41
+ priceCatalogId: string;
42
+ priority: number;
43
+ } | null>;
44
+ export declare function updateMarketPriceCatalog(db: PostgresJsDatabase, id: string, data: UpdateMarketPriceCatalogInput): Promise<{
45
+ id: string;
46
+ marketId: string;
47
+ priceCatalogId: string;
48
+ isDefault: boolean;
49
+ priority: number;
50
+ active: boolean;
51
+ notes: string | null;
52
+ metadata: Record<string, unknown> | null;
53
+ createdAt: Date;
54
+ updatedAt: Date;
55
+ } | null>;
56
+ export declare function deleteMarketPriceCatalog(db: PostgresJsDatabase, id: string): Promise<{
57
+ id: string;
58
+ } | null>;
59
+ export declare function listMarketProductRules(db: PostgresJsDatabase, query: MarketProductRuleListQuery): Promise<{
60
+ data: {
61
+ id: string;
62
+ marketId: string;
63
+ productId: string;
64
+ optionId: string | null;
65
+ priceCatalogId: string | null;
66
+ visibility: "public" | "private" | "hidden";
67
+ sellability: "sellable" | "on_request" | "unavailable";
68
+ channelScope: "internal" | "all" | "b2c" | "b2b";
69
+ active: boolean;
70
+ availableFrom: string | null;
71
+ availableTo: string | null;
72
+ notes: string | null;
73
+ createdAt: Date;
74
+ updatedAt: Date;
75
+ }[];
76
+ total: number;
77
+ limit: number;
78
+ offset: number;
79
+ }>;
80
+ export declare function getMarketProductRuleById(db: PostgresJsDatabase, id: string): Promise<{
81
+ id: string;
82
+ marketId: string;
83
+ productId: string;
84
+ optionId: string | null;
85
+ priceCatalogId: string | null;
86
+ visibility: "public" | "private" | "hidden";
87
+ sellability: "sellable" | "on_request" | "unavailable";
88
+ channelScope: "internal" | "all" | "b2c" | "b2b";
89
+ active: boolean;
90
+ availableFrom: string | null;
91
+ availableTo: string | null;
92
+ notes: string | null;
93
+ createdAt: Date;
94
+ updatedAt: Date;
95
+ } | null>;
96
+ export declare function createMarketProductRule(db: PostgresJsDatabase, data: CreateMarketProductRuleInput): Promise<{
97
+ id: string;
98
+ active: boolean;
99
+ createdAt: Date;
100
+ updatedAt: Date;
101
+ marketId: string;
102
+ notes: string | null;
103
+ priceCatalogId: string | null;
104
+ productId: string;
105
+ optionId: string | null;
106
+ visibility: "public" | "private" | "hidden";
107
+ sellability: "sellable" | "on_request" | "unavailable";
108
+ channelScope: "internal" | "all" | "b2c" | "b2b";
109
+ availableFrom: string | null;
110
+ availableTo: string | null;
111
+ } | null>;
112
+ export declare function updateMarketProductRule(db: PostgresJsDatabase, id: string, data: UpdateMarketProductRuleInput): Promise<{
113
+ id: string;
114
+ marketId: string;
115
+ productId: string;
116
+ optionId: string | null;
117
+ priceCatalogId: string | null;
118
+ visibility: "public" | "private" | "hidden";
119
+ sellability: "sellable" | "on_request" | "unavailable";
120
+ channelScope: "internal" | "all" | "b2c" | "b2b";
121
+ active: boolean;
122
+ availableFrom: string | null;
123
+ availableTo: string | null;
124
+ notes: string | null;
125
+ createdAt: Date;
126
+ updatedAt: Date;
127
+ } | null>;
128
+ export declare function deleteMarketProductRule(db: PostgresJsDatabase, id: string): Promise<{
129
+ id: string;
130
+ } | null>;
131
+ export declare function listMarketChannelRules(db: PostgresJsDatabase, query: MarketChannelRuleListQuery): Promise<{
132
+ data: {
133
+ id: string;
134
+ marketId: string;
135
+ channelId: string;
136
+ priceCatalogId: string | null;
137
+ visibility: "public" | "private" | "hidden";
138
+ sellability: "sellable" | "on_request" | "unavailable";
139
+ active: boolean;
140
+ priority: number;
141
+ notes: string | null;
142
+ createdAt: Date;
143
+ updatedAt: Date;
144
+ }[];
145
+ total: number;
146
+ limit: number;
147
+ offset: number;
148
+ }>;
149
+ export declare function getMarketChannelRuleById(db: PostgresJsDatabase, id: string): Promise<{
150
+ id: string;
151
+ marketId: string;
152
+ channelId: string;
153
+ priceCatalogId: string | null;
154
+ visibility: "public" | "private" | "hidden";
155
+ sellability: "sellable" | "on_request" | "unavailable";
156
+ active: boolean;
157
+ priority: number;
158
+ notes: string | null;
159
+ createdAt: Date;
160
+ updatedAt: Date;
161
+ } | null>;
162
+ export declare function createMarketChannelRule(db: PostgresJsDatabase, data: CreateMarketChannelRuleInput): Promise<{
163
+ id: string;
164
+ active: boolean;
165
+ createdAt: Date;
166
+ updatedAt: Date;
167
+ marketId: string;
168
+ notes: string | null;
169
+ priceCatalogId: string | null;
170
+ priority: number;
171
+ visibility: "public" | "private" | "hidden";
172
+ sellability: "sellable" | "on_request" | "unavailable";
173
+ channelId: string;
174
+ } | null>;
175
+ export declare function updateMarketChannelRule(db: PostgresJsDatabase, id: string, data: UpdateMarketChannelRuleInput): Promise<{
176
+ id: string;
177
+ marketId: string;
178
+ channelId: string;
179
+ priceCatalogId: string | null;
180
+ visibility: "public" | "private" | "hidden";
181
+ sellability: "sellable" | "on_request" | "unavailable";
182
+ active: boolean;
183
+ priority: number;
184
+ notes: string | null;
185
+ createdAt: Date;
186
+ updatedAt: Date;
187
+ } | null>;
188
+ export declare function deleteMarketChannelRule(db: PostgresJsDatabase, id: string): Promise<{
189
+ id: string;
190
+ } | null>;
191
+ //# sourceMappingURL=service-rules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-rules.d.ts","sourceRoot":"","sources":["../src/service-rules.ts"],"names":[],"mappings":"A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