@endorr/core-sdk 0.1.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.
@@ -0,0 +1,19 @@
1
+ import type { EndorrClient } from './client';
2
+ import type { EndorrFile, StorageClass } from './types';
3
+ export interface UploadOptions {
4
+ folderId?: string | null;
5
+ organizationId?: string | null;
6
+ storageClass?: StorageClass;
7
+ name?: string;
8
+ onProgress?: (fraction: number) => void;
9
+ signal?: AbortSignal;
10
+ }
11
+ /**
12
+ * Browser upload: create the file record, PUT the bytes straight to storage via the signed URL,
13
+ * then complete. Bytes never pass through the product or through Core (spec §12).
14
+ * Uses XMLHttpRequest when available so progress events work; falls back to fetch elsewhere.
15
+ */
16
+ export declare function uploadFile(client: EndorrClient, file: Blob & {
17
+ name?: string;
18
+ }, opts?: UploadOptions): Promise<EndorrFile>;
19
+ //# sourceMappingURL=upload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../src/upload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAExD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,IAAI,GAAE,aAAkB,GAAG,OAAO,CAAC,UAAU,CAAC,CAMpI"}
package/dist/upload.js ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Browser upload: create the file record, PUT the bytes straight to storage via the signed URL,
3
+ * then complete. Bytes never pass through the product or through Core (spec §12).
4
+ * Uses XMLHttpRequest when available so progress events work; falls back to fetch elsewhere.
5
+ */
6
+ export async function uploadFile(client, file, opts = {}) {
7
+ const name = opts.name ?? file.name ?? 'upload';
8
+ const mime = file.type || 'application/octet-stream';
9
+ const ticket = await client.files.createUpload({ name, mime_type: mime, size_bytes: file.size, folder_id: opts.folderId, organization_id: opts.organizationId, storage_class: opts.storageClass });
10
+ await putBytes(ticket.upload.url, ticket.upload.headers, file, opts);
11
+ return client.files.complete(ticket.file.id, { size_bytes: file.size });
12
+ }
13
+ async function putBytes(url, headers, body, opts) {
14
+ if (typeof XMLHttpRequest !== 'undefined') {
15
+ await new Promise((resolve, reject) => {
16
+ const xhr = new XMLHttpRequest();
17
+ xhr.open('PUT', url);
18
+ for (const [k, v] of Object.entries(headers))
19
+ xhr.setRequestHeader(k, v);
20
+ xhr.upload.onprogress = (e) => { if (e.lengthComputable)
21
+ opts.onProgress?.(e.loaded / e.total); };
22
+ xhr.onload = () => (xhr.status >= 200 && xhr.status < 300 ? resolve() : reject(new Error(`Storage rejected the upload (${xhr.status}).`)));
23
+ xhr.onerror = () => reject(new Error('The upload failed. Check the connection and the bucket CORS rules.'));
24
+ xhr.onabort = () => reject(new DOMException('Upload aborted', 'AbortError'));
25
+ opts.signal?.addEventListener('abort', () => xhr.abort());
26
+ xhr.send(body);
27
+ });
28
+ return;
29
+ }
30
+ const res = await fetch(url, { method: 'PUT', headers, body, signal: opts.signal });
31
+ if (!res.ok)
32
+ throw new Error(`Storage rejected the upload (${res.status}).`);
33
+ opts.onProgress?.(1);
34
+ }
35
+ //# sourceMappingURL=upload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload.js","sourceRoot":"","sources":["../src/upload.ts"],"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C,CAAC;AACvB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@endorr/core-sdk",
3
+ "version": "0.1.0",
4
+ "description": "Endorr Core client: Login with Endorr (OAuth 2.0 / OIDC), typed /v1 API, file uploads, Next.js and React helpers.",
5
+ "license": "UNLICENSED",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ },
15
+ "./nextjs": {
16
+ "types": "./dist/nextjs.d.ts",
17
+ "import": "./dist/nextjs.js"
18
+ },
19
+ "./react": {
20
+ "types": "./dist/react.d.ts",
21
+ "import": "./dist/react.js"
22
+ }
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "README.md"
27
+ ],
28
+ "dependencies": {
29
+ "jose": "^6.2.12"
30
+ },
31
+ "peerDependencies": {
32
+ "react": ">=18"
33
+ },
34
+ "peerDependenciesMeta": {
35
+ "react": {
36
+ "optional": true
37
+ }
38
+ },
39
+ "devDependencies": {
40
+ "@types/react": "^19.2.0",
41
+ "react": "^19.2.8",
42
+ "typescript": "^5.9.0"
43
+ },
44
+ "scripts": {
45
+ "build": "tsc -p tsconfig.build.json",
46
+ "typecheck": "tsc -p tsconfig.build.json --noEmit"
47
+ }
48
+ }