@reopt-ai/brandapp-sdk 3.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/CHANGELOG.md +574 -0
- package/LICENSE +21 -0
- package/README.md +468 -0
- package/dist/ai/index.d.ts +314 -0
- package/dist/ai/index.js +7 -0
- package/dist/ai-provider/index.d.ts +196 -0
- package/dist/ai-provider/index.js +703 -0
- package/dist/auth/index.d.ts +76 -0
- package/dist/auth/index.js +40 -0
- package/dist/better-auth/client.d.ts +29 -0
- package/dist/better-auth/client.js +10 -0
- package/dist/better-auth/index.d.ts +82 -0
- package/dist/better-auth/index.js +145 -0
- package/dist/chunk-6FLYVNZI.js +32 -0
- package/dist/chunk-6KPKZ7ZB.js +49 -0
- package/dist/chunk-DI6QJPTQ.js +449 -0
- package/dist/chunk-E457LO5A.js +599 -0
- package/dist/chunk-F7BXBTZI.js +54 -0
- package/dist/chunk-J5Y2GSJF.js +443 -0
- package/dist/chunk-K3YVJE6E.js +96 -0
- package/dist/chunk-KU2LN5SE.js +350 -0
- package/dist/chunk-L4DHB36G.js +75 -0
- package/dist/chunk-PJZB4VP7.js +63 -0
- package/dist/chunk-REIKXSMY.js +7 -0
- package/dist/chunk-T2WXHAAC.js +54 -0
- package/dist/chunk-TUKIYH4Q.js +112 -0
- package/dist/chunk-WSEROZVO.js +81 -0
- package/dist/chunk-YRGLBM6V.js +157 -0
- package/dist/client-BkcO-0C2.d.ts +216 -0
- package/dist/client-CN5_tNOC.d.ts +147 -0
- package/dist/client-DttyeM_h.d.ts +102 -0
- package/dist/cms/index.d.ts +137 -0
- package/dist/cms/index.js +101 -0
- package/dist/config-CtxyJsDR.d.ts +397 -0
- package/dist/dev/index.d.ts +509 -0
- package/dist/dev/index.js +3071 -0
- package/dist/eav/coerce.d.ts +42 -0
- package/dist/eav/coerce.js +65 -0
- package/dist/eav/index.d.ts +214 -0
- package/dist/eav/index.js +147 -0
- package/dist/eav/migrate.d.ts +236 -0
- package/dist/eav/migrate.js +219 -0
- package/dist/eav/schema.d.ts +260 -0
- package/dist/eav/schema.js +656 -0
- package/dist/errors-5hd5ZR-M.d.ts +158 -0
- package/dist/feedback/index.d.ts +132 -0
- package/dist/feedback/index.js +5 -0
- package/dist/files/index.d.ts +54 -0
- package/dist/files/index.js +31 -0
- package/dist/index.d.ts +221 -0
- package/dist/index.js +84 -0
- package/dist/plans/index.d.ts +140 -0
- package/dist/plans/index.js +5 -0
- package/dist/push/index.d.ts +79 -0
- package/dist/push/index.js +5 -0
- package/dist/react/hooks.d.ts +376 -0
- package/dist/react/hooks.js +421 -0
- package/dist/terms/index.d.ts +79 -0
- package/dist/terms/index.js +5 -0
- package/dist/testing/index.d.ts +154 -0
- package/dist/testing/index.js +81 -0
- package/dist/typed-client-BxOVIiMU.d.ts +40 -0
- package/dist/types-6E3ZLL9X.d.ts +24 -0
- package/dist/types-DskYLVb8.d.ts +104 -0
- package/dist/types-ckmDDW3N.d.ts +129 -0
- package/dist/webhooks/index.d.ts +140 -0
- package/dist/webhooks/index.js +142 -0
- package/docs/api-reference.md +557 -0
- package/docs/cms.md +318 -0
- package/docs/dev-server.md +164 -0
- package/docs/environment.md +211 -0
- package/docs/errors.md +290 -0
- package/docs/files.md +272 -0
- package/docs/migration.md +315 -0
- package/docs/testing.md +163 -0
- package/package.json +173 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { buildQuery } from './chunk-6FLYVNZI.js';
|
|
2
|
+
import { BaseHttpClient } from './chunk-DI6QJPTQ.js';
|
|
3
|
+
|
|
4
|
+
// src/cms/client.ts
|
|
5
|
+
function createReoptCmsClient(config) {
|
|
6
|
+
const http = new BaseHttpClient(
|
|
7
|
+
config,
|
|
8
|
+
`/api/v1/brandapp/${config.brandappId}/cms`
|
|
9
|
+
);
|
|
10
|
+
return {
|
|
11
|
+
posts: {
|
|
12
|
+
async list(query) {
|
|
13
|
+
const qs = buildQuery(query ?? {});
|
|
14
|
+
const res = await http.fetch(
|
|
15
|
+
"GET",
|
|
16
|
+
`/posts${qs}`
|
|
17
|
+
);
|
|
18
|
+
return res.data;
|
|
19
|
+
},
|
|
20
|
+
async get(postId) {
|
|
21
|
+
const res = await http.fetch(
|
|
22
|
+
"GET",
|
|
23
|
+
`/posts/${postId}`
|
|
24
|
+
);
|
|
25
|
+
return res.data;
|
|
26
|
+
},
|
|
27
|
+
/**
|
|
28
|
+
* Slug 기반 단건 조회. URL 라우트(`/blog/[slug]`)에서 id 매핑 없이 사용.
|
|
29
|
+
* 같은 slug가 여러 그룹에 있을 수 있는 경우 `groupId` 또는 `groupSlug`로 좁힐 수 있다.
|
|
30
|
+
*/
|
|
31
|
+
async getBySlug(slug, opts) {
|
|
32
|
+
const qs = buildQuery({
|
|
33
|
+
groupId: opts?.groupId,
|
|
34
|
+
groupSlug: opts?.groupSlug
|
|
35
|
+
});
|
|
36
|
+
const res = await http.fetch(
|
|
37
|
+
"GET",
|
|
38
|
+
`/posts/by-slug/${encodeURIComponent(slug)}${qs}`
|
|
39
|
+
);
|
|
40
|
+
return res.data;
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
postGroups: {
|
|
44
|
+
async list(query) {
|
|
45
|
+
const qs = buildQuery(query ?? {});
|
|
46
|
+
const res = await http.fetch("GET", `/post-groups${qs}`);
|
|
47
|
+
return res.data;
|
|
48
|
+
},
|
|
49
|
+
async get(groupId) {
|
|
50
|
+
const res = await http.fetch(
|
|
51
|
+
"GET",
|
|
52
|
+
`/post-groups/${groupId}`
|
|
53
|
+
);
|
|
54
|
+
return res.data;
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* Slug 기반 그룹 단건 조회. env var(`REOPT_*_GROUP_ID`) 대신 slug 하드코딩
|
|
58
|
+
* 패턴(`CONTENT_GROUPS.blog.slug`)을 권장.
|
|
59
|
+
*/
|
|
60
|
+
async getBySlug(slug) {
|
|
61
|
+
const res = await http.fetch(
|
|
62
|
+
"GET",
|
|
63
|
+
`/post-groups/by-slug/${encodeURIComponent(slug)}`
|
|
64
|
+
);
|
|
65
|
+
return res.data;
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
tags: {
|
|
69
|
+
/** Brand 범위 안에서 사용된 포스트 태그 목록을 반환. */
|
|
70
|
+
async list(query) {
|
|
71
|
+
const qs = buildQuery(query ?? {});
|
|
72
|
+
const res = await http.fetch("GET", `/tags${qs}`);
|
|
73
|
+
return res.data;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { createReoptCmsClient };
|
|
80
|
+
//# sourceMappingURL=chunk-WSEROZVO.js.map
|
|
81
|
+
//# sourceMappingURL=chunk-WSEROZVO.js.map
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { createManagedAbort } from './chunk-F7BXBTZI.js';
|
|
2
|
+
import { BaseHttpClient, parseFieldErrors } from './chunk-DI6QJPTQ.js';
|
|
3
|
+
import { validateConfig, SDK_VERSION, mapHttpStatusToError, ReoptSDKError } from './chunk-J5Y2GSJF.js';
|
|
4
|
+
|
|
5
|
+
// src/files/client.ts
|
|
6
|
+
var ReoptFileClient = class {
|
|
7
|
+
http;
|
|
8
|
+
timeout;
|
|
9
|
+
constructor(config) {
|
|
10
|
+
validateConfig(config);
|
|
11
|
+
const pathPrefix = `/api/v1/brandapp/${config.brandappId}/files`;
|
|
12
|
+
this.http = new BaseHttpClient(config, pathPrefix);
|
|
13
|
+
this.timeout = config.timeout ?? 3e4;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 파일 목록 조회
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const { data: files, meta } = await sdk.files.list({
|
|
21
|
+
* page: 1,
|
|
22
|
+
* limit: 20,
|
|
23
|
+
* contentType: "image/*",
|
|
24
|
+
* sortBy: "createdAt",
|
|
25
|
+
* sortOrder: "desc",
|
|
26
|
+
* });
|
|
27
|
+
* console.log(`Total: ${meta.total}`);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
async list(query) {
|
|
31
|
+
const params = new URLSearchParams();
|
|
32
|
+
if (query?.page != null) params.set("page", String(query.page));
|
|
33
|
+
if (query?.limit != null) params.set("limit", String(query.limit));
|
|
34
|
+
if (query?.contentType) params.set("contentType", query.contentType);
|
|
35
|
+
if (query?.sortBy) params.set("sortBy", query.sortBy);
|
|
36
|
+
if (query?.sortOrder) params.set("sortOrder", query.sortOrder);
|
|
37
|
+
const qs = params.toString();
|
|
38
|
+
const path = qs ? `?${qs}` : "";
|
|
39
|
+
return this.http.fetch("GET", path);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 단일 파일 조회
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* const file = await sdk.files.get("file-uuid");
|
|
47
|
+
* console.log(file.name, file.url);
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
async get(fileId) {
|
|
51
|
+
const response = await this.http.fetch(
|
|
52
|
+
"GET",
|
|
53
|
+
`/${fileId}`
|
|
54
|
+
);
|
|
55
|
+
return response.data;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 파일 삭제
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* await sdk.files.delete("file-uuid");
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
async delete(fileId) {
|
|
66
|
+
await this.http.fetch("DELETE", `/${fileId}`);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 파일 업로드
|
|
70
|
+
*
|
|
71
|
+
* FormData(multipart)로 파일을 전송합니다.
|
|
72
|
+
* BaseHttpClient는 JSON 전용이므로 globalThis.fetch를 직접 사용합니다.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* // Blob 업로드
|
|
77
|
+
* const blob = new Blob(["hello"], { type: "text/plain" });
|
|
78
|
+
* const file = await sdk.files.upload(blob, { name: "hello.txt" });
|
|
79
|
+
*
|
|
80
|
+
* // File 업로드 (브라우저)
|
|
81
|
+
* const file = await sdk.files.upload(inputEl.files[0]);
|
|
82
|
+
*
|
|
83
|
+
* // Buffer 업로드 (Node.js)
|
|
84
|
+
* const buf = fs.readFileSync("image.png");
|
|
85
|
+
* const file = await sdk.files.upload(buf, {
|
|
86
|
+
* name: "image.png",
|
|
87
|
+
* contentType: "image/png",
|
|
88
|
+
* });
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
async upload(file, options) {
|
|
92
|
+
const formData = new FormData();
|
|
93
|
+
if (file instanceof Blob) {
|
|
94
|
+
const fileName = options?.name ?? ("name" in file ? file.name : "upload");
|
|
95
|
+
formData.append("file", file, fileName);
|
|
96
|
+
} else {
|
|
97
|
+
const arrayBuffer = file.buffer.slice(
|
|
98
|
+
file.byteOffset,
|
|
99
|
+
file.byteOffset + file.byteLength
|
|
100
|
+
);
|
|
101
|
+
const blob = new Blob([arrayBuffer], {
|
|
102
|
+
type: options?.contentType ?? "application/octet-stream"
|
|
103
|
+
});
|
|
104
|
+
formData.append("file", blob, options?.name ?? "upload");
|
|
105
|
+
}
|
|
106
|
+
if (options?.name) formData.append("name", options.name);
|
|
107
|
+
if (options?.contentType)
|
|
108
|
+
formData.append("contentType", options.contentType);
|
|
109
|
+
const url = `${this.http.requestBaseUrl}/upload`;
|
|
110
|
+
const managed = createManagedAbort({
|
|
111
|
+
timeoutMs: options?.timeout ?? this.timeout,
|
|
112
|
+
external: options?.signal
|
|
113
|
+
});
|
|
114
|
+
try {
|
|
115
|
+
const response = await globalThis.fetch(url, {
|
|
116
|
+
method: "POST",
|
|
117
|
+
headers: {
|
|
118
|
+
Authorization: this.http.authorizationHeader,
|
|
119
|
+
"X-SDK-Version": `brandapp-sdk/${SDK_VERSION}`
|
|
120
|
+
// Content-Type은 FormData가 자동 설정 (boundary 포함)
|
|
121
|
+
},
|
|
122
|
+
body: formData,
|
|
123
|
+
signal: managed.signal
|
|
124
|
+
});
|
|
125
|
+
if (!response.ok) {
|
|
126
|
+
const body = await response.json().catch(() => ({}));
|
|
127
|
+
const errObj = typeof body.error === "object" ? body.error : void 0;
|
|
128
|
+
const msg = errObj?.message ?? (typeof body.error === "string" ? body.error : void 0) ?? `Upload failed with status ${response.status}`;
|
|
129
|
+
const fieldErrors = response.status === 422 ? parseFieldErrors(body) : [];
|
|
130
|
+
throw mapHttpStatusToError(
|
|
131
|
+
response.status,
|
|
132
|
+
errObj?.code,
|
|
133
|
+
msg,
|
|
134
|
+
{ method: "POST", url },
|
|
135
|
+
fieldErrors
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
const result = await response.json();
|
|
139
|
+
return result.data;
|
|
140
|
+
} catch (e) {
|
|
141
|
+
if (e instanceof ReoptSDKError) throw e;
|
|
142
|
+
if (e instanceof Error && e.name === "AbortError") {
|
|
143
|
+
throw new ReoptSDKError("Upload request timed out", 408, "TIMEOUT");
|
|
144
|
+
}
|
|
145
|
+
throw e;
|
|
146
|
+
} finally {
|
|
147
|
+
managed.cleanup();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
function createReoptFileClient(config) {
|
|
152
|
+
return new ReoptFileClient(config);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export { ReoptFileClient, createReoptFileClient };
|
|
156
|
+
//# sourceMappingURL=chunk-YRGLBM6V.js.map
|
|
157
|
+
//# sourceMappingURL=chunk-YRGLBM6V.js.map
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { S as SchemaDef, q as ReoptSDKConfig, l as EavEntity, f as CreateEntityInput, E as EavAttribute, r as UpdateEntityInput, e as CreateAttributeInput, U as UpdateAttributeInput, L as ListRecordsQuery, P as PaginatedResponse, m as EavRecord, g as CreateRecordInput, s as UpdateRecordInput, C as CountRecordsQuery, d as BulkUpdateItem, t as UpsertRecordInput, u as UpsertRecordResult, i as DeleteWhereInput, B as BackfillOptions, c as BackfillResult, p as EntityDef } from './config-CtxyJsDR.js';
|
|
2
|
+
import { E as EntityClient } from './typed-client-BxOVIiMU.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Reopt EAV Client
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { createReoptEavClient } from "@reopt-ai/brandapp-sdk/eav";
|
|
10
|
+
*
|
|
11
|
+
* const eav = createReoptEavClient({
|
|
12
|
+
* clientId: process.env.BRANDAPP_CLIENT_ID!,
|
|
13
|
+
* clientSecret: process.env.BRANDAPP_CLIENT_SECRET!,
|
|
14
|
+
* brandappId: process.env.BRANDAPP_ID!,
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* const entity = await eav.entities.create({ name: "agent_configs" });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
type ReoptEavClient<S extends SchemaDef = SchemaDef> = ReturnType<typeof createReoptEavClient<S>>;
|
|
21
|
+
declare function createReoptEavClient<S extends SchemaDef = SchemaDef>(config: ReoptSDKConfig<S>): {
|
|
22
|
+
entities: {
|
|
23
|
+
list(): Promise<EavEntity[]>;
|
|
24
|
+
create(input: CreateEntityInput): Promise<EavEntity>;
|
|
25
|
+
get(entityId: string): Promise<EavEntity & {
|
|
26
|
+
attributes: EavAttribute[];
|
|
27
|
+
}>;
|
|
28
|
+
update(entityId: string, input: UpdateEntityInput): Promise<EavEntity>;
|
|
29
|
+
delete(entityId: string): Promise<void>;
|
|
30
|
+
};
|
|
31
|
+
attributes: {
|
|
32
|
+
create(entityId: string, input: CreateAttributeInput): Promise<EavAttribute>;
|
|
33
|
+
update(entityId: string, attributeId: string, input: UpdateAttributeInput): Promise<EavAttribute>;
|
|
34
|
+
delete(entityId: string, attributeId: string): Promise<void>;
|
|
35
|
+
};
|
|
36
|
+
records: {
|
|
37
|
+
/** List records with pagination, filtering, and sorting.
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const result = await eav.records.list(entityId, {
|
|
41
|
+
* authUserId: userId,
|
|
42
|
+
* filters: [{ attributeId: "status-attr-id", operator: "eq", value: "active" }],
|
|
43
|
+
* sortBy: "createdAt",
|
|
44
|
+
* sortOrder: "desc",
|
|
45
|
+
* page: 1,
|
|
46
|
+
* limit: 50,
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
list(entityId: string, query?: ListRecordsQuery): Promise<PaginatedResponse<EavRecord>>;
|
|
51
|
+
/** Create a new record with attribute values.
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* const record = await eav.records.create(entityId, {
|
|
55
|
+
* authUserId: userId,
|
|
56
|
+
* values: { [attrs.name]: "John", [attrs.email]: "john@example.com" },
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
create(entityId: string, input: CreateRecordInput): Promise<EavRecord>;
|
|
61
|
+
/** Get a single record by ID.
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const record = await eav.records.get(entityId, recordId);
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
get(entityId: string, recordId: string): Promise<EavRecord>;
|
|
68
|
+
/** Update a record's attribute values. Only specified values are changed.
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* const updated = await eav.records.update(entityId, recordId, {
|
|
72
|
+
* values: { [attrs.status]: "completed" },
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
update(entityId: string, recordId: string, input: UpdateRecordInput): Promise<EavRecord>;
|
|
77
|
+
/** Delete a single record by ID. */
|
|
78
|
+
delete(entityId: string, recordId: string): Promise<void>;
|
|
79
|
+
/** Count records matching filters without fetching bodies.
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* // Count active tasks
|
|
83
|
+
* const count = await eav.records.count(entityId, {
|
|
84
|
+
* authUserId: userId,
|
|
85
|
+
* filters: [{ attributeId: attrs.deleted_at, operator: "is_null" }],
|
|
86
|
+
* });
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
count(entityId: string, query?: CountRecordsQuery): Promise<number>;
|
|
90
|
+
/** Delete multiple records by ID (max 100). Returns count of deleted records. */
|
|
91
|
+
bulkDelete(entityId: string, ids: string[]): Promise<number>;
|
|
92
|
+
/** Update multiple records in a single transaction (max 100).
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* const updated = await eav.records.bulkUpdate(entityId, [
|
|
96
|
+
* { id: "record-1", values: { [attrs.is_active]: false } },
|
|
97
|
+
* { id: "record-2", values: { [attrs.is_active]: false } },
|
|
98
|
+
* ]);
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
bulkUpdate(entityId: string, updates: BulkUpdateItem[]): Promise<EavRecord[]>;
|
|
102
|
+
/** Find a single record matching filters. Returns null if not found.
|
|
103
|
+
* Prefer this over list() + filter when you need exactly one record.
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* // Find setting by key
|
|
107
|
+
* const record = await eav.records.findOne(entityId, {
|
|
108
|
+
* authUserId: userId,
|
|
109
|
+
* filters: [{ attributeId: attrs.key, operator: "eq", value: "theme" }],
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
findOne(entityId: string, query?: Omit<ListRecordsQuery, "page">): Promise<EavRecord | null>;
|
|
114
|
+
/** Find a record by filters -- update if exists, create if not. Atomic operation.
|
|
115
|
+
* @returns `{ data: EavRecord, created: boolean }`
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* // Upsert a user setting
|
|
119
|
+
* const { data, created } = await eav.records.upsert(entityId, {
|
|
120
|
+
* authUserId: userId,
|
|
121
|
+
* filters: [{ attributeId: attrs.key, operator: "eq", value: "theme" }],
|
|
122
|
+
* values: { [attrs.key]: "theme", [attrs.value]: "dark" },
|
|
123
|
+
* });
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
upsert(entityId: string, input: UpsertRecordInput): Promise<UpsertRecordResult<EavRecord>>;
|
|
127
|
+
/** Create multiple records in a single transaction (max 100).
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* const records = await eav.records.bulkCreate(entityId, [
|
|
131
|
+
* { values: { [attrs.name]: "Alice" } },
|
|
132
|
+
* { values: { [attrs.name]: "Bob" } },
|
|
133
|
+
* ]);
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
bulkCreate(entityId: string, records: CreateRecordInput[]): Promise<EavRecord[]>;
|
|
137
|
+
/** Delete all records matching filters. Returns count of deleted records.
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* // Delete all inactive records
|
|
141
|
+
* const count = await eav.records.deleteWhere(entityId, {
|
|
142
|
+
* authUserId: userId,
|
|
143
|
+
* filters: [{ attributeId: attrs.status, operator: "eq", value: "inactive" }],
|
|
144
|
+
* });
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
deleteWhere(entityId: string, input: DeleteWhereInput): Promise<number>;
|
|
148
|
+
/** Iterate all records across pages as an AsyncGenerator.
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* // Stream all records
|
|
152
|
+
* for await (const record of eav.records.listAll(entityId, { authUserId: userId })) {
|
|
153
|
+
* process.stdout.write(".");
|
|
154
|
+
* }
|
|
155
|
+
*
|
|
156
|
+
* // Or collect to array
|
|
157
|
+
* import { collectAll } from "@reopt-ai/brandapp-sdk/eav";
|
|
158
|
+
* const all = await collectAll(eav.records.listAll(entityId));
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
listAll(entityId: string, query?: Omit<ListRecordsQuery, "page">): AsyncGenerator<EavRecord>;
|
|
162
|
+
/**
|
|
163
|
+
* Backfill records by streaming through pages, calling `transform` per
|
|
164
|
+
* record, and applying `update` for each non-null result.
|
|
165
|
+
*
|
|
166
|
+
* Designed for the "expand-contract" middle step of an EAV migration —
|
|
167
|
+
* e.g. copy values from a soon-to-be-deleted attribute to a new one.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* await sdk.eav.records.backfill(entityId, {
|
|
172
|
+
* filters: [{ attributeId: levelAttrId, operator: "is_null" }],
|
|
173
|
+
* concurrency: 10,
|
|
174
|
+
* transform: (r) => ({ level: r.values.tier ?? "free" }),
|
|
175
|
+
* onProgress: ({ processed, total }) =>
|
|
176
|
+
* console.log(`${processed}/${total}`),
|
|
177
|
+
* });
|
|
178
|
+
* ```
|
|
179
|
+
*
|
|
180
|
+
* Failed updates are collected in `result.failed[]` rather than aborting
|
|
181
|
+
* the run — inspect that array after the call to retry or escalate.
|
|
182
|
+
*/
|
|
183
|
+
backfill(entityId: string, opts: BackfillOptions): Promise<BackfillResult>;
|
|
184
|
+
};
|
|
185
|
+
users: {
|
|
186
|
+
getRecords(authUserId: string, query?: Omit<ListRecordsQuery, "authUserId">): Promise<PaginatedResponse<EavRecord>>;
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Fetch the server's current EAV schema fingerprint (Phase C, RFC-0005).
|
|
190
|
+
*
|
|
191
|
+
* Pair with `verifyEavSchema(localHash, client)` to detect drift between
|
|
192
|
+
* a deployed bundle and the live schema. Cacheable for ~60s — the server
|
|
193
|
+
* recomputes on every schema mutation.
|
|
194
|
+
*/
|
|
195
|
+
schemaHash(): Promise<{
|
|
196
|
+
hash: string;
|
|
197
|
+
schemaCount: number;
|
|
198
|
+
fieldCount: number;
|
|
199
|
+
generatedAt: string;
|
|
200
|
+
}>;
|
|
201
|
+
/** Create a type-safe entity-scoped client. Resolves entity name to ID automatically.
|
|
202
|
+
* Requires `schema` in SDK config for type inference.
|
|
203
|
+
* @example
|
|
204
|
+
* ```ts
|
|
205
|
+
* const contacts = sdk.eav.entity("contacts");
|
|
206
|
+
* const record = await contacts.records.create({
|
|
207
|
+
* values: { name: "John", email: "john@example.com" }, // typed!
|
|
208
|
+
* });
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
entity<K extends string & keyof S["entities"]>(name: K): EntityClient<S["entities"][K] extends EntityDef ? S["entities"][K] : EntityDef>;
|
|
212
|
+
/** Clear the entity name → ID cache and schema cache. Call after creating/deleting entities externally. */
|
|
213
|
+
invalidateCache(): void;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
export { type ReoptEavClient as R, createReoptEavClient as c };
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { q as ReoptSDKConfig } from './config-CtxyJsDR.js';
|
|
2
|
+
|
|
3
|
+
/** 파일 정보 */
|
|
4
|
+
type FileInfo = {
|
|
5
|
+
/** 파일 ID */
|
|
6
|
+
id: string;
|
|
7
|
+
/** 파일명 */
|
|
8
|
+
name: string;
|
|
9
|
+
/** 파일 URL (Vercel Blob) */
|
|
10
|
+
url: string | null;
|
|
11
|
+
/** 파일 크기 (bytes) */
|
|
12
|
+
size: number;
|
|
13
|
+
/** MIME 타입 */
|
|
14
|
+
contentType: string | null;
|
|
15
|
+
/** 저장 경로 */
|
|
16
|
+
pathname: string;
|
|
17
|
+
/** 생성일 (ISO 8601) */
|
|
18
|
+
createdAt: string;
|
|
19
|
+
/** 수정일 (ISO 8601) */
|
|
20
|
+
updatedAt: string;
|
|
21
|
+
};
|
|
22
|
+
/** 파일 목록 조회 쿼리 */
|
|
23
|
+
type FileListQuery = {
|
|
24
|
+
/** 페이지 번호 (기본 1) */
|
|
25
|
+
page?: number;
|
|
26
|
+
/** 페이지 당 항목 수 (기본 20) */
|
|
27
|
+
limit?: number;
|
|
28
|
+
/** MIME 타입 필터 (e.g. "image/png", "image/*") */
|
|
29
|
+
contentType?: string;
|
|
30
|
+
/** 정렬 기준 */
|
|
31
|
+
sortBy?: "createdAt" | "name" | "size";
|
|
32
|
+
/** 정렬 순서 */
|
|
33
|
+
sortOrder?: "asc" | "desc";
|
|
34
|
+
};
|
|
35
|
+
/** 파일 목록 응답 */
|
|
36
|
+
type FileListResponse = {
|
|
37
|
+
data: FileInfo[];
|
|
38
|
+
meta: {
|
|
39
|
+
page: number;
|
|
40
|
+
limit: number;
|
|
41
|
+
total: number;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
/** 파일 업로드 옵션 */
|
|
45
|
+
type UploadOptions = {
|
|
46
|
+
/** 파일명 (미지정 시 원본 파일명 또는 자동 생성) */
|
|
47
|
+
name?: string;
|
|
48
|
+
/** MIME 타입 (미지정 시 자동 감지) */
|
|
49
|
+
contentType?: string;
|
|
50
|
+
/** 외부 AbortSignal — 업로드 중도 취소용. SDK 타임아웃과 병합됨. */
|
|
51
|
+
signal?: AbortSignal;
|
|
52
|
+
/** 이 호출에만 적용할 타임아웃 (ms). 미지정 시 SDK 기본값. */
|
|
53
|
+
timeout?: number;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* BrandApp File 클라이언트
|
|
58
|
+
*
|
|
59
|
+
* 기존 BaseHttpClient를 활용하여 파일 목록/조회/삭제를 처리하고,
|
|
60
|
+
* 업로드는 FormData(multipart)가 필요하므로 globalThis.fetch를 직접 사용합니다.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const sdk = createReoptSDK({ ... });
|
|
65
|
+
*
|
|
66
|
+
* // List files
|
|
67
|
+
* const { data: files, meta } = await sdk.files.list({ page: 1, limit: 20 });
|
|
68
|
+
*
|
|
69
|
+
* // Get single file
|
|
70
|
+
* const file = await sdk.files.get(fileId);
|
|
71
|
+
*
|
|
72
|
+
* // Upload file
|
|
73
|
+
* const uploaded = await sdk.files.upload(blob, { name: "banner.png" });
|
|
74
|
+
* console.log(uploaded.url);
|
|
75
|
+
*
|
|
76
|
+
* // Delete file
|
|
77
|
+
* await sdk.files.delete(fileId);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
declare class ReoptFileClient {
|
|
82
|
+
private readonly http;
|
|
83
|
+
private readonly timeout;
|
|
84
|
+
constructor(config: ReoptSDKConfig);
|
|
85
|
+
/**
|
|
86
|
+
* 파일 목록 조회
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* const { data: files, meta } = await sdk.files.list({
|
|
91
|
+
* page: 1,
|
|
92
|
+
* limit: 20,
|
|
93
|
+
* contentType: "image/*",
|
|
94
|
+
* sortBy: "createdAt",
|
|
95
|
+
* sortOrder: "desc",
|
|
96
|
+
* });
|
|
97
|
+
* console.log(`Total: ${meta.total}`);
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
list(query?: FileListQuery): Promise<FileListResponse>;
|
|
101
|
+
/**
|
|
102
|
+
* 단일 파일 조회
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* const file = await sdk.files.get("file-uuid");
|
|
107
|
+
* console.log(file.name, file.url);
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
get(fileId: string): Promise<FileInfo>;
|
|
111
|
+
/**
|
|
112
|
+
* 파일 삭제
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* await sdk.files.delete("file-uuid");
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
delete(fileId: string): Promise<void>;
|
|
120
|
+
/**
|
|
121
|
+
* 파일 업로드
|
|
122
|
+
*
|
|
123
|
+
* FormData(multipart)로 파일을 전송합니다.
|
|
124
|
+
* BaseHttpClient는 JSON 전용이므로 globalThis.fetch를 직접 사용합니다.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* // Blob 업로드
|
|
129
|
+
* const blob = new Blob(["hello"], { type: "text/plain" });
|
|
130
|
+
* const file = await sdk.files.upload(blob, { name: "hello.txt" });
|
|
131
|
+
*
|
|
132
|
+
* // File 업로드 (브라우저)
|
|
133
|
+
* const file = await sdk.files.upload(inputEl.files[0]);
|
|
134
|
+
*
|
|
135
|
+
* // Buffer 업로드 (Node.js)
|
|
136
|
+
* const buf = fs.readFileSync("image.png");
|
|
137
|
+
* const file = await sdk.files.upload(buf, {
|
|
138
|
+
* name: "image.png",
|
|
139
|
+
* contentType: "image/png",
|
|
140
|
+
* });
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
upload(file: Blob | Uint8Array | File, options?: UploadOptions): Promise<FileInfo>;
|
|
144
|
+
}
|
|
145
|
+
declare function createReoptFileClient(config: ReoptSDKConfig): ReoptFileClient;
|
|
146
|
+
|
|
147
|
+
export { type FileInfo as F, ReoptFileClient as R, type UploadOptions as U, type FileListQuery as a, type FileListResponse as b, createReoptFileClient as c };
|