@sentroy-co/client-sdk 2.0.0 → 2.2.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/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/react/MediaManager.d.ts +69 -0
- package/dist/react/MediaManager.d.ts.map +1 -0
- package/dist/react/MediaManager.js +216 -0
- package/dist/react/MediaManager.js.map +1 -0
- package/dist/react/index.d.ts +4 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +13 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/lib/Lightbox.d.ts +18 -0
- package/dist/react/lib/Lightbox.d.ts.map +1 -0
- package/dist/react/lib/Lightbox.js +40 -0
- package/dist/react/lib/Lightbox.js.map +1 -0
- package/dist/react/lib/use-media-list.d.ts +21 -0
- package/dist/react/lib/use-media-list.d.ts.map +1 -0
- package/dist/react/lib/use-media-list.js +50 -0
- package/dist/react/lib/use-media-list.js.map +1 -0
- package/dist/react/lib/utils.d.ts +17 -0
- package/dist/react/lib/utils.d.ts.map +1 -0
- package/dist/react/lib/utils.js +62 -0
- package/dist/react/lib/utils.js.map +1 -0
- package/dist/resources/storage.d.ts +23 -0
- package/dist/resources/storage.d.ts.map +1 -0
- package/dist/resources/storage.js +31 -0
- package/dist/resources/storage.js.map +1 -0
- package/dist/types.d.ts +40 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +40 -4
- package/src/http.ts +151 -0
- package/src/index.ts +106 -0
- package/src/react/MediaManager.tsx +628 -0
- package/src/react/index.ts +13 -0
- package/src/react/lib/Lightbox.tsx +162 -0
- package/src/react/lib/use-media-list.ts +54 -0
- package/src/react/lib/utils.ts +73 -0
- package/src/resources/buckets.ts +50 -0
- package/src/resources/domains.ts +16 -0
- package/src/resources/inbox.ts +99 -0
- package/src/resources/mailboxes.ts +11 -0
- package/src/resources/media.ts +115 -0
- package/src/resources/send.ts +11 -0
- package/src/resources/storage.ts +28 -0
- package/src/resources/templates.ts +16 -0
- package/src/types.ts +316 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KIND_LABELS = void 0;
|
|
4
|
+
exports.cn = cn;
|
|
5
|
+
exports.formatBytes = formatBytes;
|
|
6
|
+
exports.detectKind = detectKind;
|
|
7
|
+
/**
|
|
8
|
+
* Minimal class name combiner — clsx + twMerge gibi davranır ama
|
|
9
|
+
* dependency yok. Falsy filtrele, dedup yapma. Tema override'larında
|
|
10
|
+
* Tailwind utility çakışmaları için consumer kendi cn'ini kullanırsa
|
|
11
|
+
* `className` prop'u son geldiği için doğal şekilde kazanır.
|
|
12
|
+
*/
|
|
13
|
+
function cn(...args) {
|
|
14
|
+
return args.filter(Boolean).join(" ");
|
|
15
|
+
}
|
|
16
|
+
function formatBytes(bytes, decimals = 1) {
|
|
17
|
+
if (!bytes)
|
|
18
|
+
return "0 B";
|
|
19
|
+
const units = ["B", "KB", "MB", "GB", "TB"];
|
|
20
|
+
let i = 0;
|
|
21
|
+
let v = bytes;
|
|
22
|
+
while (v >= 1024 && i < units.length - 1) {
|
|
23
|
+
v /= 1024;
|
|
24
|
+
i++;
|
|
25
|
+
}
|
|
26
|
+
return `${Number.isInteger(v) ? v : v.toFixed(decimals)} ${units[i]}`;
|
|
27
|
+
}
|
|
28
|
+
/** İlk image-like extension veya MIME → "image", "video", "audio", "pdf",
|
|
29
|
+
* "doc" (word/excel/ppt), "archive", "code", "other". */
|
|
30
|
+
function detectKind(file) {
|
|
31
|
+
const mt = (file.mimeType ?? "").toLowerCase();
|
|
32
|
+
const ext = (file.fileName ?? "").split(".").pop()?.toLowerCase() ?? "";
|
|
33
|
+
if (mt.startsWith("image/"))
|
|
34
|
+
return "image";
|
|
35
|
+
if (mt.startsWith("video/"))
|
|
36
|
+
return "video";
|
|
37
|
+
if (mt.startsWith("audio/"))
|
|
38
|
+
return "audio";
|
|
39
|
+
if (mt === "application/pdf" || ext === "pdf")
|
|
40
|
+
return "pdf";
|
|
41
|
+
if (/^(doc|docx|xls|xlsx|ppt|pptx|odt|ods|odp|txt|md|csv)$/.test(ext) ||
|
|
42
|
+
mt.startsWith("application/vnd.")) {
|
|
43
|
+
return "doc";
|
|
44
|
+
}
|
|
45
|
+
if (/^(zip|tar|gz|7z|rar|bz2)$/.test(ext))
|
|
46
|
+
return "archive";
|
|
47
|
+
if (/^(js|ts|tsx|jsx|json|html|css|scss|sh|py|go|rb|php|rs|java|c|cpp)$/.test(ext)) {
|
|
48
|
+
return "code";
|
|
49
|
+
}
|
|
50
|
+
return "other";
|
|
51
|
+
}
|
|
52
|
+
exports.KIND_LABELS = {
|
|
53
|
+
image: "Image",
|
|
54
|
+
video: "Video",
|
|
55
|
+
audio: "Audio",
|
|
56
|
+
pdf: "PDF",
|
|
57
|
+
doc: "Document",
|
|
58
|
+
archive: "Archive",
|
|
59
|
+
code: "Code",
|
|
60
|
+
other: "Other",
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/react/lib/utils.ts"],"names":[],"mappings":";;;AAMA,gBAIC;AAED,kCAUC;AAID,gCAyBC;AAnDD;;;;;GAKG;AACH,SAAgB,EAAE,CAChB,GAAG,IAAkD;IAErD,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACvC,CAAC;AAED,SAAgB,WAAW,CAAC,KAAa,EAAE,QAAQ,GAAG,CAAC;IACrD,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAA;IACxB,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;IAC3C,IAAI,CAAC,GAAG,CAAC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G,CACJ,EACD,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC;AAYY,QAAA,WAAW,GAA8B;IACpD,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;IACd,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,UAAU;IACf,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;CACf,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { HttpClient } from "../http";
|
|
2
|
+
import type { StorageQuota, StorageUsage } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* Storage observability — read-only quota + breakdown endpoints. Bucket
|
|
5
|
+
* and media CRUD lives on `client.buckets` / `client.media`.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Storage {
|
|
8
|
+
private http;
|
|
9
|
+
constructor(http: HttpClient);
|
|
10
|
+
/**
|
|
11
|
+
* Plan storage quota for the company. `used` reflects bucket totals,
|
|
12
|
+
* `mailUsed` what the mail product has stored under the same plan
|
|
13
|
+
* pool, and `limit: 0` means unlimited.
|
|
14
|
+
*/
|
|
15
|
+
quota(): Promise<StorageQuota>;
|
|
16
|
+
/**
|
|
17
|
+
* Combined dashboard payload — plan quota + per-bucket byte/file
|
|
18
|
+
* counts + per-type aggregation across the company. Single round-trip
|
|
19
|
+
* intended for usage UIs.
|
|
20
|
+
*/
|
|
21
|
+
usage(): Promise<StorageUsage>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/resources/storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAE1D;;;GAGG;AACH,qBAAa,OAAO;IACN,OAAO,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAEpC;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,YAAY,CAAC;IAIpC;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,YAAY,CAAC;CAGrC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Storage = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Storage observability — read-only quota + breakdown endpoints. Bucket
|
|
6
|
+
* and media CRUD lives on `client.buckets` / `client.media`.
|
|
7
|
+
*/
|
|
8
|
+
class Storage {
|
|
9
|
+
http;
|
|
10
|
+
constructor(http) {
|
|
11
|
+
this.http = http;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Plan storage quota for the company. `used` reflects bucket totals,
|
|
15
|
+
* `mailUsed` what the mail product has stored under the same plan
|
|
16
|
+
* pool, and `limit: 0` means unlimited.
|
|
17
|
+
*/
|
|
18
|
+
async quota() {
|
|
19
|
+
return this.http.get("/storage-quota");
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Combined dashboard payload — plan quota + per-bucket byte/file
|
|
23
|
+
* counts + per-type aggregation across the company. Single round-trip
|
|
24
|
+
* intended for usage UIs.
|
|
25
|
+
*/
|
|
26
|
+
async usage() {
|
|
27
|
+
return this.http.get("/usage");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.Storage = Storage;
|
|
31
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/resources/storage.ts"],"names":[],"mappings":";;;AAGA;;;GAGG;AACH,MAAa,OAAO;IACE;IAApB,YAAoB,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAExC;;;;OAIG;IACH,KAAK,CAAC,KAAK;QACT,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAe,gBAAgB,CAAC,CAAA;IACtD,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,KAAK;QACT,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAe,QAAQ,CAAC,CAAA;IAC9C,CAAC;CACF;AApBD,0BAoBC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -191,6 +191,11 @@ export interface Media {
|
|
|
191
191
|
caption?: string;
|
|
192
192
|
isPublic: boolean;
|
|
193
193
|
imageMeta?: MediaImageMeta;
|
|
194
|
+
/** Public bucket'larda direct CDN URL — server response'undan gelir
|
|
195
|
+
* (her zaman değil). Yoksa caller proxy/download endpoint'i kullanmalı. */
|
|
196
|
+
url?: string;
|
|
197
|
+
/** Auth'lu download URL — short-lived signed link veya proxy. */
|
|
198
|
+
downloadUrl?: string;
|
|
194
199
|
createdAt: string;
|
|
195
200
|
updatedAt: string;
|
|
196
201
|
}
|
|
@@ -226,4 +231,39 @@ export interface UploadMediaParams {
|
|
|
226
231
|
caption?: string;
|
|
227
232
|
tags?: string[];
|
|
228
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* Plan-level storage quota for the company. Mail and storage share the
|
|
236
|
+
* same byte pool; `used` reports storage's slice and `mailUsed` what mail
|
|
237
|
+
* has occupied. `limit` of `0` means the plan is unlimited.
|
|
238
|
+
*/
|
|
239
|
+
export interface StorageQuota {
|
|
240
|
+
used: number;
|
|
241
|
+
limit: number;
|
|
242
|
+
mailUsed: number;
|
|
243
|
+
planName?: string;
|
|
244
|
+
}
|
|
245
|
+
/** Per-bucket usage row inside `StorageUsage.buckets`. */
|
|
246
|
+
export interface StorageUsageBucket {
|
|
247
|
+
id: string;
|
|
248
|
+
name: string;
|
|
249
|
+
slug: string;
|
|
250
|
+
storageUsed: number;
|
|
251
|
+
fileCount: number;
|
|
252
|
+
isPublic: boolean;
|
|
253
|
+
}
|
|
254
|
+
/** Per-type aggregation row inside `StorageUsage.byType`. */
|
|
255
|
+
export interface StorageUsageByType {
|
|
256
|
+
type: MediaType;
|
|
257
|
+
count: number;
|
|
258
|
+
bytes: number;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Combined snapshot for a "Usage" dashboard: plan quota + every bucket
|
|
262
|
+
* with its byte/file counts + a media-type breakdown across the company.
|
|
263
|
+
*/
|
|
264
|
+
export interface StorageUsage {
|
|
265
|
+
quota: StorageQuota;
|
|
266
|
+
buckets: StorageUsageBucket[];
|
|
267
|
+
byType: StorageUsageByType[];
|
|
268
|
+
}
|
|
229
269
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,mBAAmB;IAClC;;;;;;;OAOG;IACH,OAAO,EAAE,MAAM,CAAA;IACf,mBAAmB;IACnB,WAAW,EAAE,MAAM,CAAA;IACnB,mEAAmE;IACnE,WAAW,EAAE,MAAM,CAAA;IACnB,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAID,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,IAAI,EAAE,CAAC,CAAA;IACP,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAID,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,QAAQ,CAAA;IACrD,WAAW,EAAE,OAAO,CAAA;IACpB,YAAY,EAAE,OAAO,CAAA;IACrB,aAAa,EAAE,OAAO,CAAA;IACtB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;CAClB;AAID,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IAC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,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,OAAO,CAAA;CAClB;AAED,6DAA6D;AAC7D,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,SAAS,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,YAAY,CAAA;IACnB,OAAO,EAAE,kBAAkB,EAAE,CAAA;IAC7B,MAAM,EAAE,kBAAkB,EAAE,CAAA;CAC7B"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentroy-co/client-sdk",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.2.0",
|
|
4
|
+
"description": "TypeScript SDK for the Sentroy platform — REST resources + React components.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./react": {
|
|
14
|
+
"types": "./dist/react/index.d.ts",
|
|
15
|
+
"import": "./dist/react/index.js",
|
|
16
|
+
"require": "./dist/react/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./types": {
|
|
19
|
+
"types": "./dist/types.d.ts",
|
|
20
|
+
"import": "./dist/types.js",
|
|
21
|
+
"require": "./dist/types.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
7
24
|
"files": [
|
|
8
|
-
"dist"
|
|
25
|
+
"dist",
|
|
26
|
+
"src"
|
|
9
27
|
],
|
|
10
28
|
"scripts": {
|
|
11
29
|
"build": "tsc",
|
|
@@ -17,7 +35,9 @@
|
|
|
17
35
|
"sdk",
|
|
18
36
|
"api",
|
|
19
37
|
"mail",
|
|
20
|
-
"typescript"
|
|
38
|
+
"typescript",
|
|
39
|
+
"react",
|
|
40
|
+
"media-manager"
|
|
21
41
|
],
|
|
22
42
|
"repository": {
|
|
23
43
|
"type": "git",
|
|
@@ -32,8 +52,24 @@
|
|
|
32
52
|
"engines": {
|
|
33
53
|
"node": ">=18.0.0"
|
|
34
54
|
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"react": ">=18.0.0",
|
|
57
|
+
"react-dom": ">=18.0.0"
|
|
58
|
+
},
|
|
59
|
+
"peerDependenciesMeta": {
|
|
60
|
+
"react": {
|
|
61
|
+
"optional": true
|
|
62
|
+
},
|
|
63
|
+
"react-dom": {
|
|
64
|
+
"optional": true
|
|
65
|
+
}
|
|
66
|
+
},
|
|
35
67
|
"devDependencies": {
|
|
36
68
|
"@types/node": "^25.6.0",
|
|
69
|
+
"@types/react": "^19.0.0",
|
|
70
|
+
"@types/react-dom": "^19.0.0",
|
|
71
|
+
"react": "^19.0.0",
|
|
72
|
+
"react-dom": "^19.0.0",
|
|
37
73
|
"typescript": "^5.5.4"
|
|
38
74
|
}
|
|
39
75
|
}
|
package/src/http.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type { ApiResponse } from "./types"
|
|
2
|
+
|
|
3
|
+
export class SentroyError extends Error {
|
|
4
|
+
constructor(
|
|
5
|
+
public readonly statusCode: number,
|
|
6
|
+
public readonly body: unknown,
|
|
7
|
+
message?: string,
|
|
8
|
+
) {
|
|
9
|
+
super(message || `Sentroy API error (${statusCode})`)
|
|
10
|
+
this.name = "SentroyError"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class HttpClient {
|
|
15
|
+
private baseUrl: string
|
|
16
|
+
private token: string
|
|
17
|
+
private timeout: number
|
|
18
|
+
|
|
19
|
+
constructor(baseUrl: string, token: string, timeout = 30_000) {
|
|
20
|
+
this.baseUrl = baseUrl.replace(/\/+$/, "")
|
|
21
|
+
this.token = token
|
|
22
|
+
this.timeout = timeout
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
private buildUrl(path: string, query?: Record<string, unknown>): string {
|
|
26
|
+
const url = new URL(`${this.baseUrl}${path}`)
|
|
27
|
+
if (query) {
|
|
28
|
+
for (const [key, value] of Object.entries(query)) {
|
|
29
|
+
if (value !== undefined && value !== null) {
|
|
30
|
+
url.searchParams.set(key, String(value))
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return url.toString()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Raw fetch — JSON parse etmez, Response döner. Binary endpoint'ler
|
|
39
|
+
* (media download) için kullanılır. Authorization header eklenir.
|
|
40
|
+
*/
|
|
41
|
+
async fetchRaw(
|
|
42
|
+
path: string,
|
|
43
|
+
init?: { method?: string; query?: Record<string, unknown> },
|
|
44
|
+
): Promise<Response> {
|
|
45
|
+
const url = this.buildUrl(path, init?.query)
|
|
46
|
+
const controller = new AbortController()
|
|
47
|
+
const timer = setTimeout(() => controller.abort(), this.timeout)
|
|
48
|
+
try {
|
|
49
|
+
return await fetch(url, {
|
|
50
|
+
method: init?.method || "GET",
|
|
51
|
+
headers: { Authorization: `Bearer ${this.token}` },
|
|
52
|
+
signal: controller.signal,
|
|
53
|
+
})
|
|
54
|
+
} finally {
|
|
55
|
+
clearTimeout(timer)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private async request<T>(
|
|
60
|
+
method: string,
|
|
61
|
+
path: string,
|
|
62
|
+
options?: {
|
|
63
|
+
query?: Record<string, unknown>
|
|
64
|
+
body?: unknown
|
|
65
|
+
},
|
|
66
|
+
): Promise<T> {
|
|
67
|
+
const url = this.buildUrl(path, options?.query)
|
|
68
|
+
const controller = new AbortController()
|
|
69
|
+
const timer = setTimeout(() => controller.abort(), this.timeout)
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
const headers: Record<string, string> = {
|
|
73
|
+
Authorization: `Bearer ${this.token}`,
|
|
74
|
+
}
|
|
75
|
+
if (options?.body) {
|
|
76
|
+
headers["Content-Type"] = "application/json"
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const res = await fetch(url, {
|
|
80
|
+
method,
|
|
81
|
+
headers,
|
|
82
|
+
body: options?.body ? JSON.stringify(options.body) : undefined,
|
|
83
|
+
signal: controller.signal,
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
const json = (await res.json()) as ApiResponse<T>
|
|
87
|
+
|
|
88
|
+
if (!res.ok) {
|
|
89
|
+
throw new SentroyError(
|
|
90
|
+
res.status,
|
|
91
|
+
json,
|
|
92
|
+
json.error || `Request failed with status ${res.status}`,
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return json.data
|
|
97
|
+
} finally {
|
|
98
|
+
clearTimeout(timer)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async get<T>(path: string, query?: Record<string, unknown>): Promise<T> {
|
|
103
|
+
return this.request<T>("GET", path, { query })
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async post<T>(path: string, body?: unknown): Promise<T> {
|
|
107
|
+
return this.request<T>("POST", path, { body })
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async put<T>(path: string, body?: unknown): Promise<T> {
|
|
111
|
+
return this.request<T>("PUT", path, { body })
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async patch<T>(path: string, body?: unknown): Promise<T> {
|
|
115
|
+
return this.request<T>("PATCH", path, { body })
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async del<T>(path: string, query?: Record<string, unknown>): Promise<T> {
|
|
119
|
+
return this.request<T>("DELETE", path, { query })
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Multipart upload. Body is a FormData; we deliberately do not set
|
|
124
|
+
* Content-Type so the runtime (browser or Node undici) writes the
|
|
125
|
+
* correct `multipart/form-data; boundary=...` header.
|
|
126
|
+
*/
|
|
127
|
+
async postForm<T>(path: string, form: FormData): Promise<T> {
|
|
128
|
+
const url = this.buildUrl(path)
|
|
129
|
+
const controller = new AbortController()
|
|
130
|
+
const timer = setTimeout(() => controller.abort(), this.timeout)
|
|
131
|
+
try {
|
|
132
|
+
const res = await fetch(url, {
|
|
133
|
+
method: "POST",
|
|
134
|
+
headers: { Authorization: `Bearer ${this.token}` },
|
|
135
|
+
body: form,
|
|
136
|
+
signal: controller.signal,
|
|
137
|
+
})
|
|
138
|
+
const json = (await res.json()) as { data: T; error?: string }
|
|
139
|
+
if (!res.ok) {
|
|
140
|
+
throw new SentroyError(
|
|
141
|
+
res.status,
|
|
142
|
+
json,
|
|
143
|
+
json.error || `Upload failed with status ${res.status}`,
|
|
144
|
+
)
|
|
145
|
+
}
|
|
146
|
+
return json.data
|
|
147
|
+
} finally {
|
|
148
|
+
clearTimeout(timer)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { HttpClient } from "./http"
|
|
2
|
+
import { Domains } from "./resources/domains"
|
|
3
|
+
import { Mailboxes } from "./resources/mailboxes"
|
|
4
|
+
import { Templates } from "./resources/templates"
|
|
5
|
+
import { Inbox } from "./resources/inbox"
|
|
6
|
+
import { Send } from "./resources/send"
|
|
7
|
+
import { Buckets } from "./resources/buckets"
|
|
8
|
+
import { MediaResource } from "./resources/media"
|
|
9
|
+
import { Storage } from "./resources/storage"
|
|
10
|
+
import type { SentroyClientConfig } from "./types"
|
|
11
|
+
|
|
12
|
+
export class Sentroy {
|
|
13
|
+
public readonly domains: Domains
|
|
14
|
+
public readonly mailboxes: Mailboxes
|
|
15
|
+
public readonly templates: Templates
|
|
16
|
+
public readonly inbox: Inbox
|
|
17
|
+
public readonly send: Send
|
|
18
|
+
public readonly buckets: Buckets
|
|
19
|
+
public readonly media: MediaResource
|
|
20
|
+
public readonly storage: Storage
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Create a new Sentroy client.
|
|
24
|
+
*
|
|
25
|
+
* Single `baseUrl` covers every resource: the platform gateway routes
|
|
26
|
+
* `/api/mail/companies/...` to the mail backend and
|
|
27
|
+
* `/api/storage/companies/...` to the storage backend. The same
|
|
28
|
+
* access token works across both.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const sentroy = new Sentroy({
|
|
33
|
+
* baseUrl: "https://sentroy.com",
|
|
34
|
+
* companySlug: "my-company",
|
|
35
|
+
* accessToken: "stk_abc123...",
|
|
36
|
+
* })
|
|
37
|
+
*
|
|
38
|
+
* const domains = await sentroy.domains.list()
|
|
39
|
+
* const buckets = await sentroy.buckets.list()
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
constructor(config: SentroyClientConfig) {
|
|
43
|
+
const root = config.baseUrl.replace(/\/+$/, "")
|
|
44
|
+
const slug = encodeURIComponent(config.companySlug)
|
|
45
|
+
|
|
46
|
+
// Mail resources hit the `/api/mail/companies` gateway path — core
|
|
47
|
+
// forwards to the mail subdomain. The SDK consumer never sees the
|
|
48
|
+
// subdomain split.
|
|
49
|
+
const mailHttp = new HttpClient(
|
|
50
|
+
`${root}/api/mail/companies/${slug}`,
|
|
51
|
+
config.accessToken,
|
|
52
|
+
config.timeout,
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
// Storage uses the same pattern via `/api/storage/companies`.
|
|
56
|
+
const storageHttp = new HttpClient(
|
|
57
|
+
`${root}/api/storage/companies/${slug}`,
|
|
58
|
+
config.accessToken,
|
|
59
|
+
config.timeout,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
this.domains = new Domains(mailHttp)
|
|
63
|
+
this.mailboxes = new Mailboxes(mailHttp)
|
|
64
|
+
this.templates = new Templates(mailHttp)
|
|
65
|
+
this.inbox = new Inbox(mailHttp)
|
|
66
|
+
this.send = new Send(mailHttp)
|
|
67
|
+
this.buckets = new Buckets(storageHttp)
|
|
68
|
+
this.media = new MediaResource(storageHttp)
|
|
69
|
+
this.storage = new Storage(storageHttp)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Re-export types
|
|
74
|
+
export type {
|
|
75
|
+
SentroyClientConfig,
|
|
76
|
+
ApiResponse,
|
|
77
|
+
Domain,
|
|
78
|
+
MailboxUser,
|
|
79
|
+
Template,
|
|
80
|
+
LocalizedString,
|
|
81
|
+
MessageAddress,
|
|
82
|
+
MessageSummary,
|
|
83
|
+
MessageDetail,
|
|
84
|
+
AttachmentInfo,
|
|
85
|
+
Mailbox,
|
|
86
|
+
InboxListParams,
|
|
87
|
+
Attachment,
|
|
88
|
+
SendParams,
|
|
89
|
+
SendResult,
|
|
90
|
+
Bucket,
|
|
91
|
+
CreateBucketParams,
|
|
92
|
+
UpdateBucketParams,
|
|
93
|
+
Media,
|
|
94
|
+
MediaType,
|
|
95
|
+
MediaThumbnail,
|
|
96
|
+
MediaImageMeta,
|
|
97
|
+
MediaListParams,
|
|
98
|
+
MediaListResult,
|
|
99
|
+
UploadMediaParams,
|
|
100
|
+
StorageQuota,
|
|
101
|
+
StorageUsage,
|
|
102
|
+
StorageUsageBucket,
|
|
103
|
+
StorageUsageByType,
|
|
104
|
+
} from "./types"
|
|
105
|
+
|
|
106
|
+
export { SentroyError } from "./http"
|