@open-loyalty/mcp-server 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 +21 -0
- package/README.md +654 -0
- package/dist/client/http.d.ts +8 -0
- package/dist/client/http.js +69 -0
- package/dist/config.d.ts +17 -0
- package/dist/config.js +40 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +20 -0
- package/dist/server.d.ts +4 -0
- package/dist/server.js +334 -0
- package/dist/tools/achievement.d.ts +983 -0
- package/dist/tools/achievement.js +311 -0
- package/dist/tools/admin.d.ts +153 -0
- package/dist/tools/admin.js +193 -0
- package/dist/tools/analytics.d.ts +162 -0
- package/dist/tools/analytics.js +245 -0
- package/dist/tools/apikey.d.ts +72 -0
- package/dist/tools/apikey.js +78 -0
- package/dist/tools/audit.d.ts +107 -0
- package/dist/tools/audit.js +90 -0
- package/dist/tools/badge.d.ts +135 -0
- package/dist/tools/badge.js +165 -0
- package/dist/tools/campaign.d.ts +1775 -0
- package/dist/tools/campaign.js +724 -0
- package/dist/tools/export.d.ts +110 -0
- package/dist/tools/export.js +147 -0
- package/dist/tools/import.d.ts +110 -0
- package/dist/tools/import.js +126 -0
- package/dist/tools/index.d.ts +22 -0
- package/dist/tools/index.js +527 -0
- package/dist/tools/member.d.ts +345 -0
- package/dist/tools/member.js +358 -0
- package/dist/tools/member.test.d.ts +1 -0
- package/dist/tools/member.test.js +213 -0
- package/dist/tools/points.d.ts +188 -0
- package/dist/tools/points.js +306 -0
- package/dist/tools/points.test.d.ts +1 -0
- package/dist/tools/points.test.js +292 -0
- package/dist/tools/reward.d.ts +261 -0
- package/dist/tools/reward.js +371 -0
- package/dist/tools/reward.test.d.ts +1 -0
- package/dist/tools/reward.test.js +240 -0
- package/dist/tools/role.d.ts +161 -0
- package/dist/tools/role.js +160 -0
- package/dist/tools/segment.d.ts +797 -0
- package/dist/tools/segment.js +299 -0
- package/dist/tools/store.d.ts +101 -0
- package/dist/tools/store.js +117 -0
- package/dist/tools/tierset.d.ts +288 -0
- package/dist/tools/tierset.js +244 -0
- package/dist/tools/transaction.d.ts +357 -0
- package/dist/tools/transaction.js +242 -0
- package/dist/tools/transaction.test.d.ts +1 -0
- package/dist/tools/transaction.test.js +235 -0
- package/dist/tools/wallet-type.d.ts +32 -0
- package/dist/tools/wallet-type.js +58 -0
- package/dist/tools/webhook.d.ts +179 -0
- package/dist/tools/webhook.js +171 -0
- package/dist/types/schemas/achievement.d.ts +1116 -0
- package/dist/types/schemas/achievement.js +172 -0
- package/dist/types/schemas/admin.d.ts +263 -0
- package/dist/types/schemas/admin.js +99 -0
- package/dist/types/schemas/analytics.d.ts +542 -0
- package/dist/types/schemas/analytics.js +130 -0
- package/dist/types/schemas/badge.d.ts +131 -0
- package/dist/types/schemas/badge.js +48 -0
- package/dist/types/schemas/campaign.d.ts +2005 -0
- package/dist/types/schemas/campaign.js +189 -0
- package/dist/types/schemas/common.d.ts +52 -0
- package/dist/types/schemas/common.js +26 -0
- package/dist/types/schemas/export.d.ts +127 -0
- package/dist/types/schemas/export.js +43 -0
- package/dist/types/schemas/import.d.ts +344 -0
- package/dist/types/schemas/import.js +68 -0
- package/dist/types/schemas/member.d.ts +443 -0
- package/dist/types/schemas/member.js +92 -0
- package/dist/types/schemas/points.d.ts +188 -0
- package/dist/types/schemas/points.js +54 -0
- package/dist/types/schemas/reward.d.ts +278 -0
- package/dist/types/schemas/reward.js +69 -0
- package/dist/types/schemas/role.d.ts +260 -0
- package/dist/types/schemas/role.js +75 -0
- package/dist/types/schemas/segment.d.ts +592 -0
- package/dist/types/schemas/segment.js +114 -0
- package/dist/types/schemas/tierset.d.ts +552 -0
- package/dist/types/schemas/tierset.js +87 -0
- package/dist/types/schemas/transaction.d.ts +1022 -0
- package/dist/types/schemas/transaction.js +63 -0
- package/dist/types/schemas/wallet-type.d.ts +99 -0
- package/dist/types/schemas/wallet-type.js +17 -0
- package/dist/types/schemas/webhook.d.ts +195 -0
- package/dist/types/schemas/webhook.js +39 -0
- package/dist/utils/cursor.d.ts +84 -0
- package/dist/utils/cursor.js +117 -0
- package/dist/utils/errors.d.ts +12 -0
- package/dist/utils/errors.js +69 -0
- package/dist/utils/pagination.d.ts +39 -0
- package/dist/utils/pagination.js +77 -0
- package/package.json +65 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export interface Export {
|
|
3
|
+
exportId: string;
|
|
4
|
+
type?: string;
|
|
5
|
+
status?: string;
|
|
6
|
+
createdAt?: string;
|
|
7
|
+
finishedAt?: string;
|
|
8
|
+
criteria?: string;
|
|
9
|
+
exportedRows?: number;
|
|
10
|
+
message?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ExportListResponse {
|
|
13
|
+
items: Export[];
|
|
14
|
+
total?: {
|
|
15
|
+
all?: number | string;
|
|
16
|
+
filtered?: number | string;
|
|
17
|
+
estimated?: boolean;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export declare const ExportCreateInputSchema: {
|
|
21
|
+
storeCode: z.ZodOptional<z.ZodString>;
|
|
22
|
+
type: z.ZodEnum<["campaignCode", "member", "memberTier", "memberSegment", "rewardFulfillment"]>;
|
|
23
|
+
filters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
24
|
+
page: z.ZodOptional<z.ZodNumber>;
|
|
25
|
+
perPage: z.ZodOptional<z.ZodNumber>;
|
|
26
|
+
};
|
|
27
|
+
export declare const ExportListInputSchema: {
|
|
28
|
+
storeCode: z.ZodOptional<z.ZodString>;
|
|
29
|
+
page: z.ZodOptional<z.ZodNumber>;
|
|
30
|
+
perPage: z.ZodOptional<z.ZodNumber>;
|
|
31
|
+
exportId: z.ZodOptional<z.ZodString>;
|
|
32
|
+
type: z.ZodOptional<z.ZodEnum<["campaignCode", "member", "memberTier", "memberSegment", "rewardFulfillment"]>>;
|
|
33
|
+
status: z.ZodOptional<z.ZodEnum<["pending", "done", "failed", "error"]>>;
|
|
34
|
+
};
|
|
35
|
+
export declare const ExportGetInputSchema: {
|
|
36
|
+
storeCode: z.ZodOptional<z.ZodString>;
|
|
37
|
+
exportId: z.ZodString;
|
|
38
|
+
};
|
|
39
|
+
export declare const ExportDownloadInputSchema: {
|
|
40
|
+
storeCode: z.ZodOptional<z.ZodString>;
|
|
41
|
+
exportId: z.ZodString;
|
|
42
|
+
};
|
|
43
|
+
export declare function exportCreate(input: {
|
|
44
|
+
storeCode?: string;
|
|
45
|
+
type: string;
|
|
46
|
+
filters?: Record<string, unknown>;
|
|
47
|
+
page?: number;
|
|
48
|
+
perPage?: number;
|
|
49
|
+
}): Promise<{
|
|
50
|
+
exportId: string;
|
|
51
|
+
}>;
|
|
52
|
+
export declare function exportList(input: {
|
|
53
|
+
storeCode?: string;
|
|
54
|
+
page?: number;
|
|
55
|
+
perPage?: number;
|
|
56
|
+
exportId?: string;
|
|
57
|
+
type?: string;
|
|
58
|
+
status?: string;
|
|
59
|
+
}): Promise<ExportListResponse>;
|
|
60
|
+
export declare function exportGet(input: {
|
|
61
|
+
storeCode?: string;
|
|
62
|
+
exportId: string;
|
|
63
|
+
}): Promise<Export>;
|
|
64
|
+
export declare function exportDownload(input: {
|
|
65
|
+
storeCode?: string;
|
|
66
|
+
exportId: string;
|
|
67
|
+
}): Promise<{
|
|
68
|
+
content: string;
|
|
69
|
+
contentType: string;
|
|
70
|
+
}>;
|
|
71
|
+
export declare const exportToolDefinitions: readonly [{
|
|
72
|
+
readonly name: "openloyalty_export_create";
|
|
73
|
+
readonly description: "Create a new data export. Returns exportId for async tracking. Export types: campaignCode (campaign redemption codes), member (member data), memberTier (member tier assignments), memberSegment (member segment membership), rewardFulfillment (reward fulfillment records). The export runs asynchronously - use export_get to check status and export_download when status is 'done'.";
|
|
74
|
+
readonly inputSchema: {
|
|
75
|
+
storeCode: z.ZodOptional<z.ZodString>;
|
|
76
|
+
type: z.ZodEnum<["campaignCode", "member", "memberTier", "memberSegment", "rewardFulfillment"]>;
|
|
77
|
+
filters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
78
|
+
page: z.ZodOptional<z.ZodNumber>;
|
|
79
|
+
perPage: z.ZodOptional<z.ZodNumber>;
|
|
80
|
+
};
|
|
81
|
+
readonly handler: typeof exportCreate;
|
|
82
|
+
}, {
|
|
83
|
+
readonly name: "openloyalty_export_list";
|
|
84
|
+
readonly description: "List exports with optional filtering. Returns paginated list of exports with exportId, type, status, createdAt, and finishedAt. Status values: pending, done, failed, error.";
|
|
85
|
+
readonly inputSchema: {
|
|
86
|
+
storeCode: z.ZodOptional<z.ZodString>;
|
|
87
|
+
page: z.ZodOptional<z.ZodNumber>;
|
|
88
|
+
perPage: z.ZodOptional<z.ZodNumber>;
|
|
89
|
+
exportId: z.ZodOptional<z.ZodString>;
|
|
90
|
+
type: z.ZodOptional<z.ZodEnum<["campaignCode", "member", "memberTier", "memberSegment", "rewardFulfillment"]>>;
|
|
91
|
+
status: z.ZodOptional<z.ZodEnum<["pending", "done", "failed", "error"]>>;
|
|
92
|
+
};
|
|
93
|
+
readonly handler: typeof exportList;
|
|
94
|
+
}, {
|
|
95
|
+
readonly name: "openloyalty_export_get";
|
|
96
|
+
readonly description: "Get export details and status. Returns exportId, type, status, createdAt, finishedAt, exportedRows, and message. Check status before downloading - export must have status 'done'.";
|
|
97
|
+
readonly inputSchema: {
|
|
98
|
+
storeCode: z.ZodOptional<z.ZodString>;
|
|
99
|
+
exportId: z.ZodString;
|
|
100
|
+
};
|
|
101
|
+
readonly handler: typeof exportGet;
|
|
102
|
+
}, {
|
|
103
|
+
readonly name: "openloyalty_export_download";
|
|
104
|
+
readonly description: "Download export file content. Returns CSV content. IMPORTANT: Only available when export status is 'done'. Check status with export_get first.";
|
|
105
|
+
readonly inputSchema: {
|
|
106
|
+
storeCode: z.ZodOptional<z.ZodString>;
|
|
107
|
+
exportId: z.ZodString;
|
|
108
|
+
};
|
|
109
|
+
readonly handler: typeof exportDownload;
|
|
110
|
+
}];
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { apiGet, apiPost } from "../client/http.js";
|
|
3
|
+
import { formatApiError } from "../utils/errors.js";
|
|
4
|
+
import { getConfig } from "../config.js";
|
|
5
|
+
import axios from "axios";
|
|
6
|
+
// Input Schemas
|
|
7
|
+
export const ExportCreateInputSchema = {
|
|
8
|
+
storeCode: z.string().optional().describe("Store code. If not provided, uses the default store code from configuration."),
|
|
9
|
+
type: z.enum([
|
|
10
|
+
"campaignCode",
|
|
11
|
+
"member",
|
|
12
|
+
"memberTier",
|
|
13
|
+
"memberSegment",
|
|
14
|
+
"rewardFulfillment",
|
|
15
|
+
]).describe("Export type. Options: campaignCode, member, memberTier, memberSegment, rewardFulfillment."),
|
|
16
|
+
filters: z.record(z.unknown()).optional().describe("Type-specific filters. For campaignCode: { campaignId?, code?, status?, codeId?, usedByMemberId?, createdAt?, usedAt? }. Filters vary by export type."),
|
|
17
|
+
page: z.number().optional().describe("Page number for export (included in export criteria)."),
|
|
18
|
+
perPage: z.number().optional().describe("Items per page for export."),
|
|
19
|
+
};
|
|
20
|
+
export const ExportListInputSchema = {
|
|
21
|
+
storeCode: z.string().optional().describe("Store code. If not provided, uses the default store code from configuration."),
|
|
22
|
+
page: z.number().optional().describe("Page number (default: 1)."),
|
|
23
|
+
perPage: z.number().optional().describe("Items per page (default: 25)."),
|
|
24
|
+
exportId: z.string().optional().describe("Filter by export ID."),
|
|
25
|
+
type: z.enum([
|
|
26
|
+
"campaignCode",
|
|
27
|
+
"member",
|
|
28
|
+
"memberTier",
|
|
29
|
+
"memberSegment",
|
|
30
|
+
"rewardFulfillment",
|
|
31
|
+
]).optional().describe("Filter by export type."),
|
|
32
|
+
status: z.enum(["pending", "done", "failed", "error"]).optional().describe("Filter by export status."),
|
|
33
|
+
};
|
|
34
|
+
export const ExportGetInputSchema = {
|
|
35
|
+
storeCode: z.string().optional().describe("Store code. If not provided, uses the default store code from configuration."),
|
|
36
|
+
exportId: z.string().describe("The export ID (UUID) to retrieve."),
|
|
37
|
+
};
|
|
38
|
+
export const ExportDownloadInputSchema = {
|
|
39
|
+
storeCode: z.string().optional().describe("Store code. If not provided, uses the default store code from configuration."),
|
|
40
|
+
exportId: z.string().describe("The export ID (UUID) to download. Export must have status 'done'."),
|
|
41
|
+
};
|
|
42
|
+
// Handler functions
|
|
43
|
+
export async function exportCreate(input) {
|
|
44
|
+
const config = getConfig();
|
|
45
|
+
const storeCode = input.storeCode || config.defaultStoreCode;
|
|
46
|
+
// Build the payload with type-specific wrapper
|
|
47
|
+
// The API expects { [type]: { ...filters, _page?, _itemsOnPage? } }
|
|
48
|
+
const innerPayload = {
|
|
49
|
+
...(input.filters || {}),
|
|
50
|
+
};
|
|
51
|
+
if (input.page)
|
|
52
|
+
innerPayload._page = input.page;
|
|
53
|
+
if (input.perPage)
|
|
54
|
+
innerPayload._itemsOnPage = input.perPage;
|
|
55
|
+
const payload = {
|
|
56
|
+
[input.type]: innerPayload,
|
|
57
|
+
};
|
|
58
|
+
try {
|
|
59
|
+
const response = await apiPost(`/${storeCode}/export/${input.type}`, payload);
|
|
60
|
+
return response;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
throw formatApiError(error, "openloyalty_export_create");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export async function exportList(input) {
|
|
67
|
+
const config = getConfig();
|
|
68
|
+
const storeCode = input.storeCode || config.defaultStoreCode;
|
|
69
|
+
const params = new URLSearchParams();
|
|
70
|
+
if (input.page)
|
|
71
|
+
params.append("_page", String(input.page));
|
|
72
|
+
if (input.perPage)
|
|
73
|
+
params.append("_itemsOnPage", String(input.perPage));
|
|
74
|
+
if (input.exportId)
|
|
75
|
+
params.append("exportId", input.exportId);
|
|
76
|
+
if (input.type)
|
|
77
|
+
params.append("type", input.type);
|
|
78
|
+
if (input.status)
|
|
79
|
+
params.append("status", input.status);
|
|
80
|
+
const queryString = params.toString();
|
|
81
|
+
const url = `/${storeCode}/export${queryString ? `?${queryString}` : ""}`;
|
|
82
|
+
try {
|
|
83
|
+
const response = await apiGet(url);
|
|
84
|
+
return response;
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
throw formatApiError(error, "openloyalty_export_list");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export async function exportGet(input) {
|
|
91
|
+
const config = getConfig();
|
|
92
|
+
const storeCode = input.storeCode || config.defaultStoreCode;
|
|
93
|
+
try {
|
|
94
|
+
const response = await apiGet(`/${storeCode}/export/${input.exportId}`);
|
|
95
|
+
return response;
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
throw formatApiError(error, "openloyalty_export_get");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export async function exportDownload(input) {
|
|
102
|
+
const config = getConfig();
|
|
103
|
+
const storeCode = input.storeCode || config.defaultStoreCode;
|
|
104
|
+
try {
|
|
105
|
+
const response = await axios.get(`${config.apiUrl}/${storeCode}/export/${input.exportId}/download`, {
|
|
106
|
+
headers: {
|
|
107
|
+
"X-AUTH-TOKEN": config.apiToken,
|
|
108
|
+
"Accept": "text/csv",
|
|
109
|
+
},
|
|
110
|
+
responseType: "text",
|
|
111
|
+
});
|
|
112
|
+
return {
|
|
113
|
+
content: response.data,
|
|
114
|
+
contentType: response.headers["content-type"] || "text/csv",
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
throw formatApiError(error, "openloyalty_export_download");
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Tool definitions
|
|
122
|
+
export const exportToolDefinitions = [
|
|
123
|
+
{
|
|
124
|
+
name: "openloyalty_export_create",
|
|
125
|
+
description: "Create a new data export. Returns exportId for async tracking. Export types: campaignCode (campaign redemption codes), member (member data), memberTier (member tier assignments), memberSegment (member segment membership), rewardFulfillment (reward fulfillment records). The export runs asynchronously - use export_get to check status and export_download when status is 'done'.",
|
|
126
|
+
inputSchema: ExportCreateInputSchema,
|
|
127
|
+
handler: exportCreate,
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: "openloyalty_export_list",
|
|
131
|
+
description: "List exports with optional filtering. Returns paginated list of exports with exportId, type, status, createdAt, and finishedAt. Status values: pending, done, failed, error.",
|
|
132
|
+
inputSchema: ExportListInputSchema,
|
|
133
|
+
handler: exportList,
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
name: "openloyalty_export_get",
|
|
137
|
+
description: "Get export details and status. Returns exportId, type, status, createdAt, finishedAt, exportedRows, and message. Check status before downloading - export must have status 'done'.",
|
|
138
|
+
inputSchema: ExportGetInputSchema,
|
|
139
|
+
handler: exportGet,
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: "openloyalty_export_download",
|
|
143
|
+
description: "Download export file content. Returns CSV content. IMPORTANT: Only available when export status is 'done'. Check status with export_get first.",
|
|
144
|
+
inputSchema: ExportDownloadInputSchema,
|
|
145
|
+
handler: exportDownload,
|
|
146
|
+
},
|
|
147
|
+
];
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export interface Import {
|
|
3
|
+
importId: string;
|
|
4
|
+
type?: string;
|
|
5
|
+
uploadedDate?: string;
|
|
6
|
+
fileName?: string;
|
|
7
|
+
itemsToImport?: number;
|
|
8
|
+
user?: string;
|
|
9
|
+
errorMessage?: string;
|
|
10
|
+
additionalData?: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
export interface ImportItem {
|
|
13
|
+
importId?: string;
|
|
14
|
+
status?: string;
|
|
15
|
+
createdAt?: string;
|
|
16
|
+
updatedAt?: string;
|
|
17
|
+
message?: string;
|
|
18
|
+
entity?: {
|
|
19
|
+
id?: string;
|
|
20
|
+
data?: Record<string, unknown>;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export interface ImportListResponse {
|
|
24
|
+
items: Import[];
|
|
25
|
+
total?: {
|
|
26
|
+
all?: number | string;
|
|
27
|
+
filtered?: number | string;
|
|
28
|
+
estimated?: boolean | number;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export interface ImportDetailsResponse {
|
|
32
|
+
items: ImportItem[];
|
|
33
|
+
total?: {
|
|
34
|
+
all?: number | string;
|
|
35
|
+
filtered?: number | string;
|
|
36
|
+
estimated?: boolean | number;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export declare const ImportCreateInputSchema: {
|
|
40
|
+
storeCode: z.ZodOptional<z.ZodString>;
|
|
41
|
+
type: z.ZodEnum<["member", "groupValue", "segmentMembers", "unitTransferAdding", "unitTransferSpending", "transaction", "campaignCode", "rewardCoupon"]>;
|
|
42
|
+
fileContent: z.ZodString;
|
|
43
|
+
fileName: z.ZodOptional<z.ZodString>;
|
|
44
|
+
};
|
|
45
|
+
export declare const ImportListInputSchema: {
|
|
46
|
+
storeCode: z.ZodOptional<z.ZodString>;
|
|
47
|
+
page: z.ZodOptional<z.ZodNumber>;
|
|
48
|
+
perPage: z.ZodOptional<z.ZodNumber>;
|
|
49
|
+
importId: z.ZodOptional<z.ZodString>;
|
|
50
|
+
type: z.ZodOptional<z.ZodEnum<["member", "groupValue", "segmentMembers", "unitTransferAdding", "unitTransferSpending", "transaction", "campaignCode", "rewardCoupon"]>>;
|
|
51
|
+
};
|
|
52
|
+
export declare const ImportGetInputSchema: {
|
|
53
|
+
storeCode: z.ZodOptional<z.ZodString>;
|
|
54
|
+
importId: z.ZodString;
|
|
55
|
+
page: z.ZodOptional<z.ZodNumber>;
|
|
56
|
+
perPage: z.ZodOptional<z.ZodNumber>;
|
|
57
|
+
};
|
|
58
|
+
export declare function importCreate(input: {
|
|
59
|
+
storeCode?: string;
|
|
60
|
+
type: string;
|
|
61
|
+
fileContent: string;
|
|
62
|
+
fileName?: string;
|
|
63
|
+
}): Promise<{
|
|
64
|
+
importId: string;
|
|
65
|
+
}>;
|
|
66
|
+
export declare function importList(input: {
|
|
67
|
+
storeCode?: string;
|
|
68
|
+
page?: number;
|
|
69
|
+
perPage?: number;
|
|
70
|
+
importId?: string;
|
|
71
|
+
type?: string;
|
|
72
|
+
}): Promise<ImportListResponse>;
|
|
73
|
+
export declare function importGet(input: {
|
|
74
|
+
storeCode?: string;
|
|
75
|
+
importId: string;
|
|
76
|
+
page?: number;
|
|
77
|
+
perPage?: number;
|
|
78
|
+
}): Promise<ImportDetailsResponse>;
|
|
79
|
+
export declare const importToolDefinitions: readonly [{
|
|
80
|
+
readonly name: "openloyalty_import_create";
|
|
81
|
+
readonly description: "Create a new bulk import from CSV content. Returns importId for async tracking. Import types: member (member data), groupValue (group values), segmentMembers (segment membership), unitTransferAdding (add points), unitTransferSpending (spend points), transaction (transactions), campaignCode (campaign codes), rewardCoupon (reward coupons). CSV format required - provide plain text CSV content.";
|
|
82
|
+
readonly inputSchema: {
|
|
83
|
+
storeCode: z.ZodOptional<z.ZodString>;
|
|
84
|
+
type: z.ZodEnum<["member", "groupValue", "segmentMembers", "unitTransferAdding", "unitTransferSpending", "transaction", "campaignCode", "rewardCoupon"]>;
|
|
85
|
+
fileContent: z.ZodString;
|
|
86
|
+
fileName: z.ZodOptional<z.ZodString>;
|
|
87
|
+
};
|
|
88
|
+
readonly handler: typeof importCreate;
|
|
89
|
+
}, {
|
|
90
|
+
readonly name: "openloyalty_import_list";
|
|
91
|
+
readonly description: "List imports with optional filtering. Returns paginated list of imports with importId, type, uploadedDate, fileName, and status information.";
|
|
92
|
+
readonly inputSchema: {
|
|
93
|
+
storeCode: z.ZodOptional<z.ZodString>;
|
|
94
|
+
page: z.ZodOptional<z.ZodNumber>;
|
|
95
|
+
perPage: z.ZodOptional<z.ZodNumber>;
|
|
96
|
+
importId: z.ZodOptional<z.ZodString>;
|
|
97
|
+
type: z.ZodOptional<z.ZodEnum<["member", "groupValue", "segmentMembers", "unitTransferAdding", "unitTransferSpending", "transaction", "campaignCode", "rewardCoupon"]>>;
|
|
98
|
+
};
|
|
99
|
+
readonly handler: typeof importList;
|
|
100
|
+
}, {
|
|
101
|
+
readonly name: "openloyalty_import_get";
|
|
102
|
+
readonly description: "Get import details and individual item statuses. Returns paginated list of import items with their success/failure status and error messages.";
|
|
103
|
+
readonly inputSchema: {
|
|
104
|
+
storeCode: z.ZodOptional<z.ZodString>;
|
|
105
|
+
importId: z.ZodString;
|
|
106
|
+
page: z.ZodOptional<z.ZodNumber>;
|
|
107
|
+
perPage: z.ZodOptional<z.ZodNumber>;
|
|
108
|
+
};
|
|
109
|
+
readonly handler: typeof importGet;
|
|
110
|
+
}];
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { apiGet } from "../client/http.js";
|
|
3
|
+
import { formatApiError } from "../utils/errors.js";
|
|
4
|
+
import { getConfig } from "../config.js";
|
|
5
|
+
import axios from "axios";
|
|
6
|
+
// Input Schemas
|
|
7
|
+
export const ImportCreateInputSchema = {
|
|
8
|
+
storeCode: z.string().optional().describe("Store code. If not provided, uses the default store code from configuration."),
|
|
9
|
+
type: z.enum([
|
|
10
|
+
"member",
|
|
11
|
+
"groupValue",
|
|
12
|
+
"segmentMembers",
|
|
13
|
+
"unitTransferAdding",
|
|
14
|
+
"unitTransferSpending",
|
|
15
|
+
"transaction",
|
|
16
|
+
"campaignCode",
|
|
17
|
+
"rewardCoupon",
|
|
18
|
+
]).describe("Import type. Options: member, groupValue, segmentMembers, unitTransferAdding, unitTransferSpending, transaction, campaignCode, rewardCoupon."),
|
|
19
|
+
fileContent: z.string().describe("CSV file content (plain text, not base64 encoded). Each line should be a comma-separated row."),
|
|
20
|
+
fileName: z.string().optional().describe("Optional file name for the import (default: import.csv)."),
|
|
21
|
+
};
|
|
22
|
+
export const ImportListInputSchema = {
|
|
23
|
+
storeCode: z.string().optional().describe("Store code. If not provided, uses the default store code from configuration."),
|
|
24
|
+
page: z.number().optional().describe("Page number (default: 1)."),
|
|
25
|
+
perPage: z.number().optional().describe("Items per page (default: 25)."),
|
|
26
|
+
importId: z.string().optional().describe("Filter by import ID."),
|
|
27
|
+
type: z.enum([
|
|
28
|
+
"member",
|
|
29
|
+
"groupValue",
|
|
30
|
+
"segmentMembers",
|
|
31
|
+
"unitTransferAdding",
|
|
32
|
+
"unitTransferSpending",
|
|
33
|
+
"transaction",
|
|
34
|
+
"campaignCode",
|
|
35
|
+
"rewardCoupon",
|
|
36
|
+
]).optional().describe("Filter by import type."),
|
|
37
|
+
};
|
|
38
|
+
export const ImportGetInputSchema = {
|
|
39
|
+
storeCode: z.string().optional().describe("Store code. If not provided, uses the default store code from configuration."),
|
|
40
|
+
importId: z.string().describe("The import ID (UUID) to retrieve."),
|
|
41
|
+
page: z.number().optional().describe("Page number for import items (default: 1)."),
|
|
42
|
+
perPage: z.number().optional().describe("Items per page for import items (default: 25)."),
|
|
43
|
+
};
|
|
44
|
+
// Handler functions
|
|
45
|
+
export async function importCreate(input) {
|
|
46
|
+
const config = getConfig();
|
|
47
|
+
const storeCode = input.storeCode || config.defaultStoreCode;
|
|
48
|
+
const fileName = input.fileName || "import.csv";
|
|
49
|
+
// Create form data for multipart upload
|
|
50
|
+
const formData = new FormData();
|
|
51
|
+
const blob = new Blob([input.fileContent], { type: "text/csv" });
|
|
52
|
+
formData.append("file", blob, fileName);
|
|
53
|
+
try {
|
|
54
|
+
const response = await axios.post(`${config.apiUrl}/${storeCode}/import/${input.type}`, formData, {
|
|
55
|
+
headers: {
|
|
56
|
+
"X-AUTH-TOKEN": config.apiToken,
|
|
57
|
+
"Content-Type": "multipart/form-data",
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
return response.data;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
throw formatApiError(error, "openloyalty_import_create");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export async function importList(input) {
|
|
67
|
+
const config = getConfig();
|
|
68
|
+
const storeCode = input.storeCode || config.defaultStoreCode;
|
|
69
|
+
const params = new URLSearchParams();
|
|
70
|
+
if (input.page)
|
|
71
|
+
params.append("_page", String(input.page));
|
|
72
|
+
if (input.perPage)
|
|
73
|
+
params.append("_itemsOnPage", String(input.perPage));
|
|
74
|
+
if (input.importId)
|
|
75
|
+
params.append("importId", input.importId);
|
|
76
|
+
if (input.type)
|
|
77
|
+
params.append("type", input.type);
|
|
78
|
+
const queryString = params.toString();
|
|
79
|
+
const url = `/${storeCode}/import${queryString ? `?${queryString}` : ""}`;
|
|
80
|
+
try {
|
|
81
|
+
const response = await apiGet(url);
|
|
82
|
+
return response;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
throw formatApiError(error, "openloyalty_import_list");
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export async function importGet(input) {
|
|
89
|
+
const config = getConfig();
|
|
90
|
+
const storeCode = input.storeCode || config.defaultStoreCode;
|
|
91
|
+
const params = new URLSearchParams();
|
|
92
|
+
if (input.page)
|
|
93
|
+
params.append("_page", String(input.page));
|
|
94
|
+
if (input.perPage)
|
|
95
|
+
params.append("_itemsOnPage", String(input.perPage));
|
|
96
|
+
const queryString = params.toString();
|
|
97
|
+
const url = `/${storeCode}/import/${input.importId}${queryString ? `?${queryString}` : ""}`;
|
|
98
|
+
try {
|
|
99
|
+
const response = await apiGet(url);
|
|
100
|
+
return response;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
throw formatApiError(error, "openloyalty_import_get");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Tool definitions
|
|
107
|
+
export const importToolDefinitions = [
|
|
108
|
+
{
|
|
109
|
+
name: "openloyalty_import_create",
|
|
110
|
+
description: "Create a new bulk import from CSV content. Returns importId for async tracking. Import types: member (member data), groupValue (group values), segmentMembers (segment membership), unitTransferAdding (add points), unitTransferSpending (spend points), transaction (transactions), campaignCode (campaign codes), rewardCoupon (reward coupons). CSV format required - provide plain text CSV content.",
|
|
111
|
+
inputSchema: ImportCreateInputSchema,
|
|
112
|
+
handler: importCreate,
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: "openloyalty_import_list",
|
|
116
|
+
description: "List imports with optional filtering. Returns paginated list of imports with importId, type, uploadedDate, fileName, and status information.",
|
|
117
|
+
inputSchema: ImportListInputSchema,
|
|
118
|
+
handler: importList,
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: "openloyalty_import_get",
|
|
122
|
+
description: "Get import details and individual item statuses. Returns paginated list of import items with their success/failure status and error messages.",
|
|
123
|
+
inputSchema: ImportGetInputSchema,
|
|
124
|
+
handler: importGet,
|
|
125
|
+
},
|
|
126
|
+
];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
type ZodShape = Record<string, z.ZodTypeAny>;
|
|
3
|
+
export interface ToolAnnotations {
|
|
4
|
+
title?: string;
|
|
5
|
+
readOnlyHint?: boolean;
|
|
6
|
+
destructiveHint?: boolean;
|
|
7
|
+
idempotentHint?: boolean;
|
|
8
|
+
openWorldHint?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface ToolDefinition {
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
inputSchema: ZodShape;
|
|
14
|
+
handler: (args: Record<string, unknown>) => Promise<unknown>;
|
|
15
|
+
}
|
|
16
|
+
export declare const toolMetadata: Record<string, {
|
|
17
|
+
title: string;
|
|
18
|
+
annotations: ToolAnnotations;
|
|
19
|
+
}>;
|
|
20
|
+
export declare function getAllTools(): ToolDefinition[];
|
|
21
|
+
export declare function getToolHandler(name: string): ((args: Record<string, unknown>) => Promise<unknown>) | undefined;
|
|
22
|
+
export {};
|