@uniforge/portal 0.1.0-alpha.2
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/dist/auth/index.d.cts +104 -0
- package/dist/auth/index.d.ts +104 -0
- package/dist/auth/index.js +194 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/index.mjs +160 -0
- package/dist/auth/index.mjs.map +1 -0
- package/dist/dashboard/index.d.cts +76 -0
- package/dist/dashboard/index.d.ts +76 -0
- package/dist/dashboard/index.js +158 -0
- package/dist/dashboard/index.js.map +1 -0
- package/dist/dashboard/index.mjs +129 -0
- package/dist/dashboard/index.mjs.map +1 -0
- package/dist/feature-flags/index.d.cts +75 -0
- package/dist/feature-flags/index.d.ts +75 -0
- package/dist/feature-flags/index.js +111 -0
- package/dist/feature-flags/index.js.map +1 -0
- package/dist/feature-flags/index.mjs +83 -0
- package/dist/feature-flags/index.mjs.map +1 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +6 -0
- package/dist/index.mjs.map +1 -0
- package/dist/merchants/index.d.cts +100 -0
- package/dist/merchants/index.d.ts +100 -0
- package/dist/merchants/index.js +120 -0
- package/dist/merchants/index.js.map +1 -0
- package/dist/merchants/index.mjs +90 -0
- package/dist/merchants/index.mjs.map +1 -0
- package/dist/metrics/index.d.cts +83 -0
- package/dist/metrics/index.d.ts +83 -0
- package/dist/metrics/index.js +112 -0
- package/dist/metrics/index.js.map +1 -0
- package/dist/metrics/index.mjs +83 -0
- package/dist/metrics/index.mjs.map +1 -0
- package/dist/tickets/index.d.cts +96 -0
- package/dist/tickets/index.d.ts +96 -0
- package/dist/tickets/index.js +102 -0
- package/dist/tickets/index.js.map +1 -0
- package/dist/tickets/index.mjs +73 -0
- package/dist/tickets/index.mjs.map +1 -0
- package/dist/webhook-logs/index.d.cts +88 -0
- package/dist/webhook-logs/index.d.ts +88 -0
- package/dist/webhook-logs/index.js +111 -0
- package/dist/webhook-logs/index.js.map +1 -0
- package/dist/webhook-logs/index.mjs +82 -0
- package/dist/webhook-logs/index.mjs.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// src/feature-flags/feature-flag-service.ts
|
|
2
|
+
var FLAG_KEY_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9_-]*$/;
|
|
3
|
+
var FeatureFlagService = class {
|
|
4
|
+
dataSource;
|
|
5
|
+
constructor(dataSource) {
|
|
6
|
+
this.dataSource = dataSource;
|
|
7
|
+
}
|
|
8
|
+
async createFlag(input) {
|
|
9
|
+
if (!FLAG_KEY_PATTERN.test(input.key)) {
|
|
10
|
+
throw new Error(
|
|
11
|
+
`Invalid flag key "${input.key}". Keys must be alphanumeric and may contain hyphens or underscores.`
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
return this.dataSource.create(input);
|
|
15
|
+
}
|
|
16
|
+
async getFlag(flagId) {
|
|
17
|
+
return this.dataSource.getById(flagId);
|
|
18
|
+
}
|
|
19
|
+
async getFlagByKey(key) {
|
|
20
|
+
return this.dataSource.getByKey(key);
|
|
21
|
+
}
|
|
22
|
+
async listFlags(filter) {
|
|
23
|
+
return this.dataSource.list(filter);
|
|
24
|
+
}
|
|
25
|
+
async updateFlag(flagId, input) {
|
|
26
|
+
return this.dataSource.update(flagId, input);
|
|
27
|
+
}
|
|
28
|
+
async deleteFlag(flagId) {
|
|
29
|
+
return this.dataSource.delete(flagId);
|
|
30
|
+
}
|
|
31
|
+
async toggleFlag(flagId, enabled) {
|
|
32
|
+
return this.dataSource.update(flagId, { enabled });
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// src/feature-flags/feature-flag-evaluator.ts
|
|
37
|
+
function hashToPercentage(input) {
|
|
38
|
+
let hash = 5381;
|
|
39
|
+
for (let i = 0; i < input.length; i++) {
|
|
40
|
+
hash = hash * 33 ^ input.charCodeAt(i);
|
|
41
|
+
}
|
|
42
|
+
return Math.abs(hash) % 100;
|
|
43
|
+
}
|
|
44
|
+
var FeatureFlagEvaluator = class {
|
|
45
|
+
dataSource;
|
|
46
|
+
constructor(dataSource) {
|
|
47
|
+
this.dataSource = dataSource;
|
|
48
|
+
}
|
|
49
|
+
async evaluate(flagKey, shopDomain) {
|
|
50
|
+
const flag = await this.dataSource.getByKey(flagKey);
|
|
51
|
+
if (!flag) {
|
|
52
|
+
return { flagKey, enabled: false, reason: "not_found" };
|
|
53
|
+
}
|
|
54
|
+
if (!flag.enabled) {
|
|
55
|
+
return { flagKey, enabled: false, reason: "disabled" };
|
|
56
|
+
}
|
|
57
|
+
if (flag.excludedShops.includes(shopDomain)) {
|
|
58
|
+
return { flagKey, enabled: false, reason: "excluded" };
|
|
59
|
+
}
|
|
60
|
+
if (flag.targetShops.includes(shopDomain)) {
|
|
61
|
+
return { flagKey, enabled: true, reason: "targeted" };
|
|
62
|
+
}
|
|
63
|
+
if (flag.rolloutPercentage > 0) {
|
|
64
|
+
const bucket = hashToPercentage(flagKey + shopDomain);
|
|
65
|
+
const enabled = bucket < flag.rolloutPercentage;
|
|
66
|
+
return { flagKey, enabled, reason: "rollout" };
|
|
67
|
+
}
|
|
68
|
+
return { flagKey, enabled: flag.enabled, reason: "default" };
|
|
69
|
+
}
|
|
70
|
+
async evaluateAll(shopDomain) {
|
|
71
|
+
const { flags } = await this.dataSource.list();
|
|
72
|
+
const result = {};
|
|
73
|
+
for (const flag of flags) {
|
|
74
|
+
result[flag.key] = await this.evaluate(flag.key, shopDomain);
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
export {
|
|
80
|
+
FeatureFlagEvaluator,
|
|
81
|
+
FeatureFlagService
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/feature-flags/feature-flag-service.ts","../../src/feature-flags/feature-flag-evaluator.ts"],"sourcesContent":["import type { FeatureFlagDataSource } from './feature-flag-data-source.js';\nimport type {\n FeatureFlag,\n FeatureFlagCreateInput,\n FeatureFlagFilter,\n FeatureFlagListResult,\n FeatureFlagUpdateInput,\n} from './types.js';\n\nconst FLAG_KEY_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9_-]*$/;\n\nexport class FeatureFlagService {\n private readonly dataSource: FeatureFlagDataSource;\n\n constructor(dataSource: FeatureFlagDataSource) {\n this.dataSource = dataSource;\n }\n\n async createFlag(input: FeatureFlagCreateInput): Promise<FeatureFlag> {\n if (!FLAG_KEY_PATTERN.test(input.key)) {\n throw new Error(\n `Invalid flag key \"${input.key}\". Keys must be alphanumeric and may contain hyphens or underscores.`,\n );\n }\n return this.dataSource.create(input);\n }\n\n async getFlag(flagId: string): Promise<FeatureFlag | null> {\n return this.dataSource.getById(flagId);\n }\n\n async getFlagByKey(key: string): Promise<FeatureFlag | null> {\n return this.dataSource.getByKey(key);\n }\n\n async listFlags(\n filter?: FeatureFlagFilter,\n ): Promise<FeatureFlagListResult> {\n return this.dataSource.list(filter);\n }\n\n async updateFlag(\n flagId: string,\n input: FeatureFlagUpdateInput,\n ): Promise<FeatureFlag | null> {\n return this.dataSource.update(flagId, input);\n }\n\n async deleteFlag(flagId: string): Promise<boolean> {\n return this.dataSource.delete(flagId);\n }\n\n async toggleFlag(\n flagId: string,\n enabled: boolean,\n ): Promise<FeatureFlag | null> {\n return this.dataSource.update(flagId, { enabled });\n }\n}\n","import type { FeatureFlagDataSource } from './feature-flag-data-source.js';\nimport type { FeatureFlagEvaluation } from './types.js';\n\n/**\n * Simple djb2 hash for deterministic rollout.\n * Returns a value in [0, 99].\n */\nfunction hashToPercentage(input: string): number {\n let hash = 5381;\n for (let i = 0; i < input.length; i++) {\n hash = (hash * 33) ^ input.charCodeAt(i);\n }\n return Math.abs(hash) % 100;\n}\n\nexport class FeatureFlagEvaluator {\n private readonly dataSource: FeatureFlagDataSource;\n\n constructor(dataSource: FeatureFlagDataSource) {\n this.dataSource = dataSource;\n }\n\n async evaluate(\n flagKey: string,\n shopDomain: string,\n ): Promise<FeatureFlagEvaluation> {\n const flag = await this.dataSource.getByKey(flagKey);\n\n if (!flag) {\n return { flagKey, enabled: false, reason: 'not_found' };\n }\n\n if (!flag.enabled) {\n return { flagKey, enabled: false, reason: 'disabled' };\n }\n\n if (flag.excludedShops.includes(shopDomain)) {\n return { flagKey, enabled: false, reason: 'excluded' };\n }\n\n if (flag.targetShops.includes(shopDomain)) {\n return { flagKey, enabled: true, reason: 'targeted' };\n }\n\n if (flag.rolloutPercentage > 0) {\n const bucket = hashToPercentage(flagKey + shopDomain);\n const enabled = bucket < flag.rolloutPercentage;\n return { flagKey, enabled, reason: 'rollout' };\n }\n\n return { flagKey, enabled: flag.enabled, reason: 'default' };\n }\n\n async evaluateAll(\n shopDomain: string,\n ): Promise<Record<string, FeatureFlagEvaluation>> {\n const { flags } = await this.dataSource.list();\n const result: Record<string, FeatureFlagEvaluation> = {};\n\n for (const flag of flags) {\n result[flag.key] = await this.evaluate(flag.key, shopDomain);\n }\n\n return result;\n }\n}\n"],"mappings":";AASA,IAAM,mBAAmB;AAElB,IAAM,qBAAN,MAAyB;AAAA,EACb;AAAA,EAEjB,YAAY,YAAmC;AAC7C,SAAK,aAAa;AAAA,EACpB;AAAA,EAEA,MAAM,WAAW,OAAqD;AACpE,QAAI,CAAC,iBAAiB,KAAK,MAAM,GAAG,GAAG;AACrC,YAAM,IAAI;AAAA,QACR,qBAAqB,MAAM,GAAG;AAAA,MAChC;AAAA,IACF;AACA,WAAO,KAAK,WAAW,OAAO,KAAK;AAAA,EACrC;AAAA,EAEA,MAAM,QAAQ,QAA6C;AACzD,WAAO,KAAK,WAAW,QAAQ,MAAM;AAAA,EACvC;AAAA,EAEA,MAAM,aAAa,KAA0C;AAC3D,WAAO,KAAK,WAAW,SAAS,GAAG;AAAA,EACrC;AAAA,EAEA,MAAM,UACJ,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AAQ,UAAU;AAAA,IAC/C;AAEA,WAAO,EAAE,SAAS,SAAS,KAAK,SAAS,QAAQ,UAAU;AAAA,EAC7D;AAAA,EAEA,MAAM,YACJ,YACgD;AAChD,UAAM,EAAE,MAAM,IAAI,MAAM,KAAK,WAAW,KAAK;AAC7C,UAAM,SAAgD,CAAC;AAEvD,eAAW,QAAQ,OAAO;AACxB,aAAO,KAAK,GAAG,IAAI,MAAM,KAAK,SAAS,KAAK,KAAK,UAAU;AAAA,IAC7D;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @uniforge/portal — Developer Portal Backend
|
|
3
|
+
*
|
|
4
|
+
* Provides backend services for the developer portal:
|
|
5
|
+
* - Auth: developer team authentication and permission guards
|
|
6
|
+
* - Dashboard: KPI aggregation and activity feeds
|
|
7
|
+
* - Merchants: merchant list, search, detail, activity, and usage
|
|
8
|
+
* - Metrics: API metrics collection and error tracking
|
|
9
|
+
* - Webhook Logs: webhook delivery logging, search, and replay
|
|
10
|
+
* - Feature Flags: feature flag management with rollout strategies
|
|
11
|
+
* - Tickets: support ticket management and tracking
|
|
12
|
+
*/
|
|
13
|
+
declare const VERSION = "0.4.0";
|
|
14
|
+
|
|
15
|
+
export { VERSION };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @uniforge/portal — Developer Portal Backend
|
|
3
|
+
*
|
|
4
|
+
* Provides backend services for the developer portal:
|
|
5
|
+
* - Auth: developer team authentication and permission guards
|
|
6
|
+
* - Dashboard: KPI aggregation and activity feeds
|
|
7
|
+
* - Merchants: merchant list, search, detail, activity, and usage
|
|
8
|
+
* - Metrics: API metrics collection and error tracking
|
|
9
|
+
* - Webhook Logs: webhook delivery logging, search, and replay
|
|
10
|
+
* - Feature Flags: feature flag management with rollout strategies
|
|
11
|
+
* - Tickets: support ticket management and tracking
|
|
12
|
+
*/
|
|
13
|
+
declare const VERSION = "0.4.0";
|
|
14
|
+
|
|
15
|
+
export { VERSION };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
VERSION: () => VERSION
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var VERSION = "0.4.0";
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
VERSION
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @uniforge/portal — Developer Portal Backend\n *\n * Provides backend services for the developer portal:\n * - Auth: developer team authentication and permission guards\n * - Dashboard: KPI aggregation and activity feeds\n * - Merchants: merchant list, search, detail, activity, and usage\n * - Metrics: API metrics collection and error tracking\n * - Webhook Logs: webhook delivery logging, search, and replay\n * - Feature Flags: feature flag management with rollout strategies\n * - Tickets: support ticket management and tracking\n */\n\nexport const VERSION = '0.4.0';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAaO,IAAM,UAAU;","names":[]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @uniforge/portal — Developer Portal Backend\n *\n * Provides backend services for the developer portal:\n * - Auth: developer team authentication and permission guards\n * - Dashboard: KPI aggregation and activity feeds\n * - Merchants: merchant list, search, detail, activity, and usage\n * - Metrics: API metrics collection and error tracking\n * - Webhook Logs: webhook delivery logging, search, and replay\n * - Feature Flags: feature flag management with rollout strategies\n * - Tickets: support ticket management and tracking\n */\n\nexport const VERSION = '0.4.0';\n"],"mappings":";AAaO,IAAM,UAAU;","names":[]}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merchant module types for the developer portal.
|
|
3
|
+
*/
|
|
4
|
+
type MerchantStatus = 'ACTIVE' | 'INACTIVE' | 'UNINSTALLED' | 'FROZEN' | 'PENDING';
|
|
5
|
+
interface MerchantInfo {
|
|
6
|
+
id: string;
|
|
7
|
+
shopDomain: string;
|
|
8
|
+
shopName: string;
|
|
9
|
+
plan: string;
|
|
10
|
+
status: MerchantStatus;
|
|
11
|
+
installedAt: string;
|
|
12
|
+
lastActiveAt: string | null;
|
|
13
|
+
email: string | null;
|
|
14
|
+
}
|
|
15
|
+
interface MerchantActivity {
|
|
16
|
+
id: string;
|
|
17
|
+
title: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
timestamp: string;
|
|
20
|
+
status?: 'success' | 'warning' | 'error' | 'info';
|
|
21
|
+
}
|
|
22
|
+
interface MerchantUsage {
|
|
23
|
+
label: string;
|
|
24
|
+
current: number;
|
|
25
|
+
limit: number;
|
|
26
|
+
unit?: string;
|
|
27
|
+
}
|
|
28
|
+
interface MerchantDetailData {
|
|
29
|
+
merchant: MerchantInfo;
|
|
30
|
+
activities: MerchantActivity[];
|
|
31
|
+
usage: MerchantUsage[];
|
|
32
|
+
}
|
|
33
|
+
interface MerchantListResult {
|
|
34
|
+
merchants: MerchantInfo[];
|
|
35
|
+
total: number;
|
|
36
|
+
page: number;
|
|
37
|
+
pageSize: number;
|
|
38
|
+
}
|
|
39
|
+
interface MerchantSearchParams {
|
|
40
|
+
query?: string;
|
|
41
|
+
status?: MerchantStatus;
|
|
42
|
+
plan?: string;
|
|
43
|
+
page?: number;
|
|
44
|
+
pageSize?: number;
|
|
45
|
+
sortBy?: string;
|
|
46
|
+
sortOrder?: 'asc' | 'desc';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface MerchantDataSource {
|
|
50
|
+
findMerchants(params: MerchantSearchParams): Promise<MerchantListResult>;
|
|
51
|
+
findMerchantById(merchantId: string): Promise<MerchantInfo | null>;
|
|
52
|
+
findMerchantByDomain(shopDomain: string): Promise<MerchantInfo | null>;
|
|
53
|
+
countMerchants(filter?: {
|
|
54
|
+
status?: MerchantStatus;
|
|
55
|
+
}): Promise<number>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
declare class MerchantService {
|
|
59
|
+
private readonly dataSource;
|
|
60
|
+
constructor(dataSource: MerchantDataSource);
|
|
61
|
+
listMerchants(params?: MerchantSearchParams): Promise<MerchantListResult>;
|
|
62
|
+
getMerchantById(merchantId: string): Promise<MerchantInfo | null>;
|
|
63
|
+
getMerchantByDomain(shopDomain: string): Promise<MerchantInfo | null>;
|
|
64
|
+
searchMerchants(query: string, params?: Omit<MerchantSearchParams, 'query'>): Promise<MerchantListResult>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface MerchantActivityDataSource {
|
|
68
|
+
getActivities(merchantId: string, limit?: number): Promise<MerchantActivity[]>;
|
|
69
|
+
addActivity(merchantId: string, activity: Omit<MerchantActivity, 'id'>): Promise<MerchantActivity>;
|
|
70
|
+
}
|
|
71
|
+
declare class MerchantActivityService {
|
|
72
|
+
private readonly dataSource;
|
|
73
|
+
constructor(dataSource: MerchantActivityDataSource);
|
|
74
|
+
getActivities(merchantId: string, limit?: number): Promise<MerchantActivity[]>;
|
|
75
|
+
recordActivity(merchantId: string, title: string, options?: {
|
|
76
|
+
description?: string;
|
|
77
|
+
status?: MerchantActivity['status'];
|
|
78
|
+
}): Promise<MerchantActivity>;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
interface MerchantUsageDataSource {
|
|
82
|
+
getUsage(merchantId: string): Promise<MerchantUsage[]>;
|
|
83
|
+
updateUsage(merchantId: string, label: string, current: number): Promise<MerchantUsage>;
|
|
84
|
+
}
|
|
85
|
+
declare class MerchantUsageService {
|
|
86
|
+
private readonly dataSource;
|
|
87
|
+
constructor(dataSource: MerchantUsageDataSource);
|
|
88
|
+
getUsage(merchantId: string): Promise<MerchantUsage[]>;
|
|
89
|
+
updateUsage(merchantId: string, label: string, current: number): Promise<MerchantUsage>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
declare class MerchantDetailService {
|
|
93
|
+
private readonly merchantService;
|
|
94
|
+
private readonly activityService;
|
|
95
|
+
private readonly usageService;
|
|
96
|
+
constructor(merchantService: MerchantService, activityService: MerchantActivityService, usageService: MerchantUsageService);
|
|
97
|
+
getMerchantDetail(merchantId: string): Promise<MerchantDetailData | null>;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { type MerchantActivity, type MerchantActivityDataSource, MerchantActivityService, type MerchantDataSource, type MerchantDetailData, MerchantDetailService, type MerchantInfo, type MerchantListResult, type MerchantSearchParams, MerchantService, type MerchantStatus, type MerchantUsage, type MerchantUsageDataSource, MerchantUsageService };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merchant module types for the developer portal.
|
|
3
|
+
*/
|
|
4
|
+
type MerchantStatus = 'ACTIVE' | 'INACTIVE' | 'UNINSTALLED' | 'FROZEN' | 'PENDING';
|
|
5
|
+
interface MerchantInfo {
|
|
6
|
+
id: string;
|
|
7
|
+
shopDomain: string;
|
|
8
|
+
shopName: string;
|
|
9
|
+
plan: string;
|
|
10
|
+
status: MerchantStatus;
|
|
11
|
+
installedAt: string;
|
|
12
|
+
lastActiveAt: string | null;
|
|
13
|
+
email: string | null;
|
|
14
|
+
}
|
|
15
|
+
interface MerchantActivity {
|
|
16
|
+
id: string;
|
|
17
|
+
title: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
timestamp: string;
|
|
20
|
+
status?: 'success' | 'warning' | 'error' | 'info';
|
|
21
|
+
}
|
|
22
|
+
interface MerchantUsage {
|
|
23
|
+
label: string;
|
|
24
|
+
current: number;
|
|
25
|
+
limit: number;
|
|
26
|
+
unit?: string;
|
|
27
|
+
}
|
|
28
|
+
interface MerchantDetailData {
|
|
29
|
+
merchant: MerchantInfo;
|
|
30
|
+
activities: MerchantActivity[];
|
|
31
|
+
usage: MerchantUsage[];
|
|
32
|
+
}
|
|
33
|
+
interface MerchantListResult {
|
|
34
|
+
merchants: MerchantInfo[];
|
|
35
|
+
total: number;
|
|
36
|
+
page: number;
|
|
37
|
+
pageSize: number;
|
|
38
|
+
}
|
|
39
|
+
interface MerchantSearchParams {
|
|
40
|
+
query?: string;
|
|
41
|
+
status?: MerchantStatus;
|
|
42
|
+
plan?: string;
|
|
43
|
+
page?: number;
|
|
44
|
+
pageSize?: number;
|
|
45
|
+
sortBy?: string;
|
|
46
|
+
sortOrder?: 'asc' | 'desc';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface MerchantDataSource {
|
|
50
|
+
findMerchants(params: MerchantSearchParams): Promise<MerchantListResult>;
|
|
51
|
+
findMerchantById(merchantId: string): Promise<MerchantInfo | null>;
|
|
52
|
+
findMerchantByDomain(shopDomain: string): Promise<MerchantInfo | null>;
|
|
53
|
+
countMerchants(filter?: {
|
|
54
|
+
status?: MerchantStatus;
|
|
55
|
+
}): Promise<number>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
declare class MerchantService {
|
|
59
|
+
private readonly dataSource;
|
|
60
|
+
constructor(dataSource: MerchantDataSource);
|
|
61
|
+
listMerchants(params?: MerchantSearchParams): Promise<MerchantListResult>;
|
|
62
|
+
getMerchantById(merchantId: string): Promise<MerchantInfo | null>;
|
|
63
|
+
getMerchantByDomain(shopDomain: string): Promise<MerchantInfo | null>;
|
|
64
|
+
searchMerchants(query: string, params?: Omit<MerchantSearchParams, 'query'>): Promise<MerchantListResult>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface MerchantActivityDataSource {
|
|
68
|
+
getActivities(merchantId: string, limit?: number): Promise<MerchantActivity[]>;
|
|
69
|
+
addActivity(merchantId: string, activity: Omit<MerchantActivity, 'id'>): Promise<MerchantActivity>;
|
|
70
|
+
}
|
|
71
|
+
declare class MerchantActivityService {
|
|
72
|
+
private readonly dataSource;
|
|
73
|
+
constructor(dataSource: MerchantActivityDataSource);
|
|
74
|
+
getActivities(merchantId: string, limit?: number): Promise<MerchantActivity[]>;
|
|
75
|
+
recordActivity(merchantId: string, title: string, options?: {
|
|
76
|
+
description?: string;
|
|
77
|
+
status?: MerchantActivity['status'];
|
|
78
|
+
}): Promise<MerchantActivity>;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
interface MerchantUsageDataSource {
|
|
82
|
+
getUsage(merchantId: string): Promise<MerchantUsage[]>;
|
|
83
|
+
updateUsage(merchantId: string, label: string, current: number): Promise<MerchantUsage>;
|
|
84
|
+
}
|
|
85
|
+
declare class MerchantUsageService {
|
|
86
|
+
private readonly dataSource;
|
|
87
|
+
constructor(dataSource: MerchantUsageDataSource);
|
|
88
|
+
getUsage(merchantId: string): Promise<MerchantUsage[]>;
|
|
89
|
+
updateUsage(merchantId: string, label: string, current: number): Promise<MerchantUsage>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
declare class MerchantDetailService {
|
|
93
|
+
private readonly merchantService;
|
|
94
|
+
private readonly activityService;
|
|
95
|
+
private readonly usageService;
|
|
96
|
+
constructor(merchantService: MerchantService, activityService: MerchantActivityService, usageService: MerchantUsageService);
|
|
97
|
+
getMerchantDetail(merchantId: string): Promise<MerchantDetailData | null>;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { type MerchantActivity, type MerchantActivityDataSource, MerchantActivityService, type MerchantDataSource, type MerchantDetailData, MerchantDetailService, type MerchantInfo, type MerchantListResult, type MerchantSearchParams, MerchantService, type MerchantStatus, type MerchantUsage, type MerchantUsageDataSource, MerchantUsageService };
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/merchants/index.ts
|
|
21
|
+
var merchants_exports = {};
|
|
22
|
+
__export(merchants_exports, {
|
|
23
|
+
MerchantActivityService: () => MerchantActivityService,
|
|
24
|
+
MerchantDetailService: () => MerchantDetailService,
|
|
25
|
+
MerchantService: () => MerchantService,
|
|
26
|
+
MerchantUsageService: () => MerchantUsageService
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(merchants_exports);
|
|
29
|
+
|
|
30
|
+
// src/merchants/merchant-service.ts
|
|
31
|
+
var MerchantService = class {
|
|
32
|
+
constructor(dataSource) {
|
|
33
|
+
this.dataSource = dataSource;
|
|
34
|
+
}
|
|
35
|
+
async listMerchants(params) {
|
|
36
|
+
return this.dataSource.findMerchants({
|
|
37
|
+
page: 1,
|
|
38
|
+
pageSize: 20,
|
|
39
|
+
...params
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async getMerchantById(merchantId) {
|
|
43
|
+
return this.dataSource.findMerchantById(merchantId);
|
|
44
|
+
}
|
|
45
|
+
async getMerchantByDomain(shopDomain) {
|
|
46
|
+
return this.dataSource.findMerchantByDomain(shopDomain);
|
|
47
|
+
}
|
|
48
|
+
async searchMerchants(query, params) {
|
|
49
|
+
return this.dataSource.findMerchants({
|
|
50
|
+
page: 1,
|
|
51
|
+
pageSize: 20,
|
|
52
|
+
...params,
|
|
53
|
+
query
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// src/merchants/merchant-activity-service.ts
|
|
59
|
+
var MerchantActivityService = class {
|
|
60
|
+
constructor(dataSource) {
|
|
61
|
+
this.dataSource = dataSource;
|
|
62
|
+
}
|
|
63
|
+
async getActivities(merchantId, limit) {
|
|
64
|
+
return this.dataSource.getActivities(merchantId, limit);
|
|
65
|
+
}
|
|
66
|
+
async recordActivity(merchantId, title, options) {
|
|
67
|
+
const activity = {
|
|
68
|
+
title,
|
|
69
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
70
|
+
};
|
|
71
|
+
if (options?.description !== void 0) {
|
|
72
|
+
activity.description = options.description;
|
|
73
|
+
}
|
|
74
|
+
if (options?.status !== void 0) {
|
|
75
|
+
activity.status = options.status;
|
|
76
|
+
}
|
|
77
|
+
return this.dataSource.addActivity(merchantId, activity);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/merchants/merchant-usage-service.ts
|
|
82
|
+
var MerchantUsageService = class {
|
|
83
|
+
constructor(dataSource) {
|
|
84
|
+
this.dataSource = dataSource;
|
|
85
|
+
}
|
|
86
|
+
async getUsage(merchantId) {
|
|
87
|
+
return this.dataSource.getUsage(merchantId);
|
|
88
|
+
}
|
|
89
|
+
async updateUsage(merchantId, label, current) {
|
|
90
|
+
return this.dataSource.updateUsage(merchantId, label, current);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// src/merchants/merchant-detail-service.ts
|
|
95
|
+
var MerchantDetailService = class {
|
|
96
|
+
constructor(merchantService, activityService, usageService) {
|
|
97
|
+
this.merchantService = merchantService;
|
|
98
|
+
this.activityService = activityService;
|
|
99
|
+
this.usageService = usageService;
|
|
100
|
+
}
|
|
101
|
+
async getMerchantDetail(merchantId) {
|
|
102
|
+
const merchant = await this.merchantService.getMerchantById(merchantId);
|
|
103
|
+
if (!merchant) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
const [activities, usage] = await Promise.all([
|
|
107
|
+
this.activityService.getActivities(merchantId),
|
|
108
|
+
this.usageService.getUsage(merchantId)
|
|
109
|
+
]);
|
|
110
|
+
return { merchant, activities, usage };
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
114
|
+
0 && (module.exports = {
|
|
115
|
+
MerchantActivityService,
|
|
116
|
+
MerchantDetailService,
|
|
117
|
+
MerchantService,
|
|
118
|
+
MerchantUsageService
|
|
119
|
+
});
|
|
120
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/merchants/index.ts","../../src/merchants/merchant-service.ts","../../src/merchants/merchant-activity-service.ts","../../src/merchants/merchant-usage-service.ts","../../src/merchants/merchant-detail-service.ts"],"sourcesContent":["export type {\n MerchantStatus,\n MerchantInfo,\n MerchantActivity,\n MerchantUsage,\n MerchantDetailData,\n MerchantListResult,\n MerchantSearchParams,\n} from './types.js';\n\nexport type { MerchantDataSource } from './merchant-data-source.js';\nexport { MerchantService } from './merchant-service.js';\n\nexport type { MerchantActivityDataSource } from './merchant-activity-service.js';\nexport { MerchantActivityService } from './merchant-activity-service.js';\n\nexport type { MerchantUsageDataSource } from './merchant-usage-service.js';\nexport { MerchantUsageService } from './merchant-usage-service.js';\n\nexport { MerchantDetailService } from './merchant-detail-service.js';\n","import type { MerchantDataSource } from './merchant-data-source.js';\nimport type {\n MerchantInfo,\n MerchantListResult,\n MerchantSearchParams,\n} from './types.js';\n\nexport class MerchantService {\n constructor(private readonly dataSource: MerchantDataSource) {}\n\n async listMerchants(\n params?: MerchantSearchParams,\n ): Promise<MerchantListResult> {\n return this.dataSource.findMerchants({\n page: 1,\n pageSize: 20,\n ...params,\n });\n }\n\n async getMerchantById(merchantId: string): Promise<MerchantInfo | null> {\n return this.dataSource.findMerchantById(merchantId);\n }\n\n async getMerchantByDomain(shopDomain: string): Promise<MerchantInfo | null> {\n return this.dataSource.findMerchantByDomain(shopDomain);\n }\n\n async searchMerchants(\n query: string,\n params?: Omit<MerchantSearchParams, 'query'>,\n ): Promise<MerchantListResult> {\n return this.dataSource.findMerchants({\n page: 1,\n pageSize: 20,\n ...params,\n query,\n });\n }\n}\n","import type { MerchantActivity } from './types.js';\n\nexport interface MerchantActivityDataSource {\n getActivities(\n merchantId: string,\n limit?: number,\n ): Promise<MerchantActivity[]>;\n addActivity(\n merchantId: string,\n activity: Omit<MerchantActivity, 'id'>,\n ): Promise<MerchantActivity>;\n}\n\nexport class MerchantActivityService {\n constructor(private readonly dataSource: MerchantActivityDataSource) {}\n\n async getActivities(\n merchantId: string,\n limit?: number,\n ): Promise<MerchantActivity[]> {\n return this.dataSource.getActivities(merchantId, limit);\n }\n\n async recordActivity(\n merchantId: string,\n title: string,\n options?: {\n description?: string;\n status?: MerchantActivity['status'];\n },\n ): Promise<MerchantActivity> {\n const activity: Omit<MerchantActivity, 'id'> = {\n title,\n timestamp: new Date().toISOString(),\n };\n if (options?.description !== undefined) {\n activity.description = options.description;\n }\n if (options?.status !== undefined) {\n activity.status = options.status;\n }\n return this.dataSource.addActivity(merchantId, activity);\n }\n}\n","import type { MerchantUsage } from './types.js';\n\nexport interface MerchantUsageDataSource {\n getUsage(merchantId: string): Promise<MerchantUsage[]>;\n updateUsage(\n merchantId: string,\n label: string,\n current: number,\n ): Promise<MerchantUsage>;\n}\n\nexport class MerchantUsageService {\n constructor(private readonly dataSource: MerchantUsageDataSource) {}\n\n async getUsage(merchantId: string): Promise<MerchantUsage[]> {\n return this.dataSource.getUsage(merchantId);\n }\n\n async updateUsage(\n merchantId: string,\n label: string,\n current: number,\n ): Promise<MerchantUsage> {\n return this.dataSource.updateUsage(merchantId, label, current);\n }\n}\n","import type { MerchantActivityService } from './merchant-activity-service.js';\nimport type { MerchantService } from './merchant-service.js';\nimport type { MerchantUsageService } from './merchant-usage-service.js';\nimport type { MerchantDetailData } from './types.js';\n\nexport class MerchantDetailService {\n constructor(\n private readonly merchantService: MerchantService,\n private readonly activityService: MerchantActivityService,\n private readonly usageService: MerchantUsageService,\n ) {}\n\n async getMerchantDetail(\n merchantId: string,\n ): Promise<MerchantDetailData | null> {\n const merchant =\n await this.merchantService.getMerchantById(merchantId);\n if (!merchant) {\n return null;\n }\n\n const [activities, usage] = await Promise.all([\n this.activityService.getActivities(merchantId),\n this.usageService.getUsage(merchantId),\n ]);\n\n return { merchant, activities, usage };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOO,IAAM,kBAAN,MAAsB;AAAA,EAC3B,YAA6B,YAAgC;AAAhC;AAAA,EAAiC;AAAA,EAE9D,MAAM,cAC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N,MAA4B;AAAA,EACjC,YACmB,iBACA,iBACA,cACjB;AAHiB;AACA;AACA;AAAA,EAChB;AAAA,EAEH,MAAM,kBACJ,YACoC;AACpC,UAAM,WACJ,MAAM,KAAK,gBAAgB,gBAAgB,UAAU;AACvD,QAAI,CAAC,UAAU;AACb,aAAO;AAAA,IACT;AAEA,UAAM,CAAC,YAAY,KAAK,IAAI,MAAM,QAAQ,IAAI;AAAA,MAC5C,KAAK,gBAAgB,cAAc,UAAU;AAAA,MAC7C,KAAK,aAAa,SAAS,UAAU;AAAA,IACvC,CAAC;AAED,WAAO,EAAE,UAAU,YAAY,MAAM;AAAA,EACvC;AACF;","names":[]}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// src/merchants/merchant-service.ts
|
|
2
|
+
var MerchantService = class {
|
|
3
|
+
constructor(dataSource) {
|
|
4
|
+
this.dataSource = dataSource;
|
|
5
|
+
}
|
|
6
|
+
async listMerchants(params) {
|
|
7
|
+
return this.dataSource.findMerchants({
|
|
8
|
+
page: 1,
|
|
9
|
+
pageSize: 20,
|
|
10
|
+
...params
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
async getMerchantById(merchantId) {
|
|
14
|
+
return this.dataSource.findMerchantById(merchantId);
|
|
15
|
+
}
|
|
16
|
+
async getMerchantByDomain(shopDomain) {
|
|
17
|
+
return this.dataSource.findMerchantByDomain(shopDomain);
|
|
18
|
+
}
|
|
19
|
+
async searchMerchants(query, params) {
|
|
20
|
+
return this.dataSource.findMerchants({
|
|
21
|
+
page: 1,
|
|
22
|
+
pageSize: 20,
|
|
23
|
+
...params,
|
|
24
|
+
query
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// src/merchants/merchant-activity-service.ts
|
|
30
|
+
var MerchantActivityService = class {
|
|
31
|
+
constructor(dataSource) {
|
|
32
|
+
this.dataSource = dataSource;
|
|
33
|
+
}
|
|
34
|
+
async getActivities(merchantId, limit) {
|
|
35
|
+
return this.dataSource.getActivities(merchantId, limit);
|
|
36
|
+
}
|
|
37
|
+
async recordActivity(merchantId, title, options) {
|
|
38
|
+
const activity = {
|
|
39
|
+
title,
|
|
40
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
41
|
+
};
|
|
42
|
+
if (options?.description !== void 0) {
|
|
43
|
+
activity.description = options.description;
|
|
44
|
+
}
|
|
45
|
+
if (options?.status !== void 0) {
|
|
46
|
+
activity.status = options.status;
|
|
47
|
+
}
|
|
48
|
+
return this.dataSource.addActivity(merchantId, activity);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// src/merchants/merchant-usage-service.ts
|
|
53
|
+
var MerchantUsageService = class {
|
|
54
|
+
constructor(dataSource) {
|
|
55
|
+
this.dataSource = dataSource;
|
|
56
|
+
}
|
|
57
|
+
async getUsage(merchantId) {
|
|
58
|
+
return this.dataSource.getUsage(merchantId);
|
|
59
|
+
}
|
|
60
|
+
async updateUsage(merchantId, label, current) {
|
|
61
|
+
return this.dataSource.updateUsage(merchantId, label, current);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// src/merchants/merchant-detail-service.ts
|
|
66
|
+
var MerchantDetailService = class {
|
|
67
|
+
constructor(merchantService, activityService, usageService) {
|
|
68
|
+
this.merchantService = merchantService;
|
|
69
|
+
this.activityService = activityService;
|
|
70
|
+
this.usageService = usageService;
|
|
71
|
+
}
|
|
72
|
+
async getMerchantDetail(merchantId) {
|
|
73
|
+
const merchant = await this.merchantService.getMerchantById(merchantId);
|
|
74
|
+
if (!merchant) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
const [activities, usage] = await Promise.all([
|
|
78
|
+
this.activityService.getActivities(merchantId),
|
|
79
|
+
this.usageService.getUsage(merchantId)
|
|
80
|
+
]);
|
|
81
|
+
return { merchant, activities, usage };
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
export {
|
|
85
|
+
MerchantActivityService,
|
|
86
|
+
MerchantDetailService,
|
|
87
|
+
MerchantService,
|
|
88
|
+
MerchantUsageService
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/merchants/merchant-service.ts","../../src/merchants/merchant-activity-service.ts","../../src/merchants/merchant-usage-service.ts","../../src/merchants/merchant-detail-service.ts"],"sourcesContent":["import type { MerchantDataSource } from './merchant-data-source.js';\nimport type {\n MerchantInfo,\n MerchantListResult,\n MerchantSearchParams,\n} from './types.js';\n\nexport class MerchantService {\n constructor(private readonly dataSource: MerchantDataSource) {}\n\n async listMerchants(\n params?: MerchantSearchParams,\n ): Promise<MerchantListResult> {\n return this.dataSource.findMerchants({\n page: 1,\n pageSize: 20,\n ...params,\n });\n }\n\n async getMerchantById(merchantId: string): Promise<MerchantInfo | null> {\n return this.dataSource.findMerchantById(merchantId);\n }\n\n async getMerchantByDomain(shopDomain: string): Promise<MerchantInfo | null> {\n return this.dataSource.findMerchantByDomain(shopDomain);\n }\n\n async searchMerchants(\n query: string,\n params?: Omit<MerchantSearchParams, 'query'>,\n ): Promise<MerchantListResult> {\n return this.dataSource.findMerchants({\n page: 1,\n pageSize: 20,\n ...params,\n query,\n });\n }\n}\n","import type { MerchantActivity } from './types.js';\n\nexport interface MerchantActivityDataSource {\n getActivities(\n merchantId: string,\n limit?: number,\n ): Promise<MerchantActivity[]>;\n addActivity(\n merchantId: string,\n activity: Omit<MerchantActivity, 'id'>,\n ): Promise<MerchantActivity>;\n}\n\nexport class MerchantActivityService {\n constructor(private readonly dataSource: MerchantActivityDataSource) {}\n\n async getActivities(\n merchantId: string,\n limit?: number,\n ): Promise<MerchantActivity[]> {\n return this.dataSource.getActivities(merchantId, limit);\n }\n\n async recordActivity(\n merchantId: string,\n title: string,\n options?: {\n description?: string;\n status?: MerchantActivity['status'];\n },\n ): Promise<MerchantActivity> {\n const activity: Omit<MerchantActivity, 'id'> = {\n title,\n timestamp: new Date().toISOString(),\n };\n if (options?.description !== undefined) {\n activity.description = options.description;\n }\n if (options?.status !== undefined) {\n activity.status = options.status;\n }\n return this.dataSource.addActivity(merchantId, activity);\n }\n}\n","import type { MerchantUsage } from './types.js';\n\nexport interface MerchantUsageDataSource {\n getUsage(merchantId: string): Promise<MerchantUsage[]>;\n updateUsage(\n merchantId: string,\n label: string,\n current: number,\n ): Promise<MerchantUsage>;\n}\n\nexport class MerchantUsageService {\n constructor(private readonly dataSource: MerchantUsageDataSource) {}\n\n async getUsage(merchantId: string): Promise<MerchantUsage[]> {\n return this.dataSource.getUsage(merchantId);\n }\n\n async updateUsage(\n merchantId: string,\n label: string,\n current: number,\n ): Promise<MerchantUsage> {\n return this.dataSource.updateUsage(merchantId, label, current);\n }\n}\n","import type { MerchantActivityService } from './merchant-activity-service.js';\nimport type { MerchantService } from './merchant-service.js';\nimport type { MerchantUsageService } from './merchant-usage-service.js';\nimport type { MerchantDetailData } from './types.js';\n\nexport class MerchantDetailService {\n constructor(\n private readonly merchantService: MerchantService,\n private readonly activityService: MerchantActivityService,\n private readonly usageService: MerchantUsageService,\n ) {}\n\n async getMerchantDetail(\n merchantId: string,\n ): Promise<MerchantDetailData | null> {\n const merchant =\n await this.merchantService.getMerchantById(merchantId);\n if (!merchant) {\n return null;\n }\n\n const [activities, usage] = await Promise.all([\n this.activityService.getActivities(merchantId),\n this.usageService.getUsage(merchantId),\n ]);\n\n return { merchant, activities, usage };\n }\n}\n"],"mappings":";AAOO,IAAM,kBAAN,MAAsB;AAAA,EAC3B,YAA6B,YAAgC;AAAhC;AAAA,EAAiC;AAAA,EAE9D,MAAM,cACJ,QAC6B;AAC7B,WAAO,KAAK,WAAW,cAAc;AAAA,MACnC,MAAM;AAAA,MACN,UAAU;AAAA,MACV,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,gBAAgB,YAAkD;AACtE,WAAO,KAAK,WAAW,iBAAiB,UAAU;AAA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