leemage-sdk 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,190 @@
1
+ # leemage-sdk
2
+
3
+ Leemage 파일 관리 플랫폼을 위한 TypeScript SDK입니다.
4
+
5
+ ## 설치
6
+
7
+ ```bash
8
+ npm install leemage-sdk
9
+ # 또는
10
+ yarn add leemage-sdk
11
+ # 또는
12
+ pnpm add leemage-sdk
13
+ ```
14
+
15
+ ## 사용법
16
+
17
+ ### 클라이언트 생성
18
+
19
+ ```typescript
20
+ import { LeemageClient } from "leemage-sdk";
21
+
22
+ const client = new LeemageClient({
23
+ apiKey: "your-api-key",
24
+ baseUrl: "https://your-leemage-instance.com",
25
+ // allowInsecureHttp: true, // 로컬 개발에서만 사용
26
+ });
27
+ ```
28
+
29
+ ### 프로젝트 관리
30
+
31
+ ```typescript
32
+ // 프로젝트 목록 조회
33
+ const projects = await client.projects.list();
34
+
35
+ // 프로젝트 상세 조회 (파일 목록 포함)
36
+ const project = await client.projects.get("projectId");
37
+ console.log(project.files);
38
+
39
+ // 프로젝트 생성
40
+ const newProject = await client.projects.create({
41
+ name: "My Website Assets",
42
+ description: "웹사이트에서 사용할 이미지 모음",
43
+ storageProvider: "OCI", // 또는 "R2"
44
+ });
45
+
46
+ // 프로젝트 삭제
47
+ await client.projects.delete("projectId");
48
+ ```
49
+
50
+ ### 파일 업로드
51
+
52
+ SDK는 복잡한 Presigned URL 업로드 플로우를 `upload()` 메서드 하나로 추상화합니다.
53
+
54
+ ```typescript
55
+ // 브라우저에서
56
+ const input = document.querySelector('input[type="file"]');
57
+ const file = input.files[0];
58
+
59
+ const uploadedFile = await client.files.upload("projectId", file, {
60
+ // 이미지 변환 옵션 (이미지 파일에만 적용)
61
+ variants: [
62
+ { sizeLabel: "max800", format: "webp" },
63
+ { sizeLabel: "1200x800", format: "avif" },
64
+ ],
65
+ // 진행 상태 콜백
66
+ onProgress: (progress) => {
67
+ console.log(`Stage: ${progress.stage}, Percent: ${progress.percent}`);
68
+ },
69
+ });
70
+
71
+ console.log(uploadedFile.variants); // 변환된 이미지 URL들
72
+ ```
73
+
74
+ #### Node.js에서
75
+
76
+ ```typescript
77
+ import { readFile } from "fs/promises";
78
+ import { LeemageClient } from "leemage-sdk";
79
+
80
+ const client = new LeemageClient({
81
+ apiKey: "your-api-key",
82
+ baseUrl: "https://your-leemage-instance.com",
83
+ });
84
+
85
+ const buffer = await readFile("./image.jpg");
86
+ const file = {
87
+ name: "image.jpg",
88
+ type: "image/jpeg",
89
+ size: buffer.byteLength,
90
+ arrayBuffer: async () => buffer,
91
+ };
92
+
93
+ const uploadedFile = await client.files.upload("projectId", file);
94
+ ```
95
+
96
+ ### 파일 삭제
97
+
98
+ ```typescript
99
+ await client.files.delete("projectId", "fileId");
100
+ ```
101
+
102
+ ## 이미지 변환 옵션
103
+
104
+ ### 크기 프리셋
105
+
106
+ - `source` - 원본 크기
107
+ - `max300` - 최대 300px
108
+ - `max800` - 최대 800px
109
+ - `max1920` - 최대 1920px
110
+ - `WIDTHxHEIGHT` - 커스텀 크기 (예: `1200x800`)
111
+
112
+ ### 포맷
113
+
114
+ - `png`
115
+ - `jpeg`
116
+ - `avif`
117
+ - `webp`
118
+
119
+ ## 에러 처리
120
+
121
+ SDK는 타입화된 에러 클래스를 제공합니다:
122
+
123
+ ```typescript
124
+ import {
125
+ LeemageClient,
126
+ AuthenticationError,
127
+ PermissionDeniedError,
128
+ RateLimitError,
129
+ NotFoundError,
130
+ ValidationError,
131
+ FileTooLargeError,
132
+ } from "leemage-sdk";
133
+
134
+ try {
135
+ await client.files.upload("projectId", file);
136
+ } catch (error) {
137
+ if (error instanceof AuthenticationError) {
138
+ console.error("API 키를 확인하세요");
139
+ } else if (error instanceof PermissionDeniedError) {
140
+ console.error("권한이 없습니다");
141
+ } else if (error instanceof RateLimitError) {
142
+ console.error(`요청 한도 초과, ${error.retryAfter ?? 0}초 후 재시도`);
143
+ } else if (error instanceof NotFoundError) {
144
+ console.error("프로젝트를 찾을 수 없습니다");
145
+ } else if (error instanceof ValidationError) {
146
+ console.error("잘못된 요청:", error.errors);
147
+ } else if (error instanceof FileTooLargeError) {
148
+ console.error("파일이 너무 큽니다");
149
+ }
150
+ }
151
+ ```
152
+
153
+ ## TypeScript 지원
154
+
155
+ 이 SDK는 TypeScript로 작성되었으며, 모든 타입이 내보내집니다:
156
+
157
+ ```typescript
158
+ import type {
159
+ Project,
160
+ ProjectDetails,
161
+ FileResponse,
162
+ VariantOption,
163
+ ImageVariantData,
164
+ } from "leemage-sdk";
165
+ ```
166
+
167
+ ## 개발 (API 변경 시)
168
+
169
+ API 스펙이 변경되면 SDK 타입을 동기화해야 합니다:
170
+
171
+ ```bash
172
+ # 루트 디렉토리에서
173
+ npm run sdk:sync
174
+
175
+ # 또는 packages/sdk에서
176
+ npm run sync # 타입 생성 + 빌드
177
+ npm run generate # 타입 생성만
178
+ ```
179
+
180
+ ### npm 배포
181
+
182
+ ```bash
183
+ cd packages/sdk
184
+ npm version patch # 0.1.0 → 0.1.1
185
+ npm publish
186
+ ```
187
+
188
+ ## 라이선스
189
+
190
+ MIT