@rebalworks/transfer-react 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/LICENSE +8 -0
- package/README.md +72 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +47 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +1 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
rebalTransfer — Proprietary Software License
|
|
2
|
+
Copyright (c) 2026 rebalworks CO., LTD. All Rights Reserved.
|
|
3
|
+
|
|
4
|
+
This package is proprietary and confidential. Unauthorized copying,
|
|
5
|
+
modification, distribution, or use of this software, via any medium, is
|
|
6
|
+
strictly prohibited without prior written permission from rebalworks CO., LTD.
|
|
7
|
+
|
|
8
|
+
For licensing inquiries, contact: byhaejin@f-m.kr
|
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# @rebalworks/transfer-react
|
|
2
|
+
|
|
3
|
+
React hooks for rebalTransfer uploads.
|
|
4
|
+
|
|
5
|
+
Use this package when a React or Next.js screen needs file upload state without
|
|
6
|
+
building its own transfer orchestration.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @rebalworks/transfer-react
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Hooks
|
|
15
|
+
|
|
16
|
+
| Hook | Purpose |
|
|
17
|
+
| --- | --- |
|
|
18
|
+
| `useTransferUpload` | Starts an upload and exposes progress, completion, abort, and error state. |
|
|
19
|
+
| `useStorageProfiles` | Loads the storage profiles configured on the rebalTransfer server. |
|
|
20
|
+
|
|
21
|
+
## Upload Example
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
'use client';
|
|
25
|
+
|
|
26
|
+
import { useTransferUpload } from '@rebalworks/transfer-react';
|
|
27
|
+
|
|
28
|
+
export function UploadField() {
|
|
29
|
+
const upload = useTransferUpload({
|
|
30
|
+
apiBase: 'https://transfer.example.com/api/v1/sessions',
|
|
31
|
+
storageProfile: 'google-drive-main',
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<>
|
|
36
|
+
<input
|
|
37
|
+
type="file"
|
|
38
|
+
onChange={(event) => {
|
|
39
|
+
const file = event.currentTarget.files?.[0];
|
|
40
|
+
if (file) upload.upload(file);
|
|
41
|
+
}}
|
|
42
|
+
/>
|
|
43
|
+
|
|
44
|
+
<progress value={upload.progress?.percent ?? 0} max={100} />
|
|
45
|
+
|
|
46
|
+
<button type="button" onClick={() => void upload.abort()}>
|
|
47
|
+
Cancel
|
|
48
|
+
</button>
|
|
49
|
+
</>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Storage Profiles
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import { useStorageProfiles } from '@rebalworks/transfer-react';
|
|
58
|
+
|
|
59
|
+
const { profiles, loading, error, reload } = useStorageProfiles({
|
|
60
|
+
apiRoot: 'https://transfer.example.com/api/v1',
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Package Contents
|
|
65
|
+
|
|
66
|
+
The npm package contains minified JavaScript, public TypeScript declarations,
|
|
67
|
+
README, LICENSE, and package metadata only. It does not include source maps,
|
|
68
|
+
test files, or original TypeScript sources.
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
Proprietary. See `LICENSE`.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var react=require('react'),transferSdk=require('@rebalworks/transfer-sdk');var V={profiles:[],loading:false};function K(n={}){let{apiRoot:r,authToken:p,enabled:T=true}=n,l=react.useRef(null),f=react.useRef(true),[E,S]=react.useState(V),g=react.useCallback(async()=>{l.current?.abort();let u=new AbortController;l.current=u,S(a=>({...a,loading:true,error:void 0}));try{let a=await transferSdk.listStorageProfiles({...r!==void 0?{apiRoot:r}:{},...p!==void 0?{authToken:p}:{},signal:u.signal}),d=a.find(t=>t.defaultProfile);return f.current&&l.current===u&&S({profiles:a,...d!==void 0?{defaultProfile:d}:{},loading:!1}),a}catch(a){let d=j(a);throw f.current&&l.current===u&&S(t=>({...t,loading:false,error:d})),d}},[r,p]);return react.useEffect(()=>(f.current=true,T&&g(),()=>{f.current=false,l.current?.abort();}),[T,g]),{...E,reload:g}}function j(n){return n instanceof Error?n:new Error(String(n))}var x={phase:"idle"};function Q(n={}){let{abortOnUnmount:r=false,apiBase:p,authToken:T,chunkSize:l,forceMainThread:f,retries:E,resumeSessionId:S,sha256:g,signal:u,storageProfile:a,workerPoolSize:d}=n,t=react.useRef(true),i=react.useRef(null),U=react.useRef(null),[y,h]=react.useState(x),s=react.useCallback(()=>{U.current?.(),U.current=null;},[]),z=react.useCallback((P,v={})=>{s();let k=W(P,{apiBase:p,authToken:T,chunkSize:l,forceMainThread:f,retries:E,resumeSessionId:S,sha256:g,signal:u,storageProfile:a,workerPoolSize:d,...v}),o=transferSdk.createTransferSession(k);i.current=o,h({phase:k.sha256===void 0&&!k.forceMainThread?"hashing":"uploading"});let H=[o.on("sha256:progress",e=>{m({phase:e.percent>=100?"uploading":"hashing",sha256Progress:e});}),o.on("progress",e=>{m({phase:"uploading",progress:e});}),o.on("chunk:done",e=>{m({phase:"uploading",lastChunk:e});}),o.on("session:complete",e=>{D(e);}),o.on("session:error",e=>{C(e.error,e.cancelled);})];return U.current=()=>{for(let e of H)e();},o.sessionId.then(e=>m({sessionId:e})).catch(e=>C(I(e),w(e))),o.done.then(e=>{m({phase:"completed",session:e});}).catch(e=>C(I(e),w(e))),o;function m(e){!t.current||i.current!==o||h(c=>({...c,...e,error:e.phase==="error"?e.error:c.error}));}function D(e){!t.current||i.current!==o||(s(),h(c=>({...c,phase:"completed",session:e.session,error:void 0})));}function C(e,c){!t.current||i.current!==o||(s(),h(N=>({...N,phase:c?"aborted":"error",error:c?void 0:e})));}},[p,T,l,s,f,E,S,g,u,a,d]),A=react.useCallback(async()=>{let P=i.current;P!==null&&(await P.abort(),t.current&&i.current===P&&(s(),h(v=>({...v,phase:"aborted",error:void 0}))));},[s]),M=react.useCallback(()=>{s(),i.current=null,h(x);},[s]);return react.useEffect(()=>(t.current=true,()=>{t.current=false,s(),r&&i.current?.abort();}),[r,s]),{...y,uploading:y.phase==="hashing"||y.phase==="uploading",completed:y.phase==="completed",aborted:y.phase==="aborted",upload:z,abort:A,reset:M,handle:i.current}}function W(n,r){return {file:n,...r.apiBase!==void 0?{apiBase:r.apiBase}:{},...r.authToken!==void 0?{authToken:r.authToken}:{},...r.chunkSize!==void 0?{chunkSize:r.chunkSize}:{},...r.forceMainThread!==void 0?{forceMainThread:r.forceMainThread}:{},...r.retries!==void 0?{retries:r.retries}:{},...r.resumeSessionId!==void 0?{resumeSessionId:r.resumeSessionId}:{},...r.sha256!==void 0?{sha256:r.sha256}:{},...r.signal!==void 0?{signal:r.signal}:{},...r.storageProfile!==void 0?{storageProfile:r.storageProfile}:{},...r.workerPoolSize!==void 0?{workerPoolSize:r.workerPoolSize}:{}}}function I(n){return n instanceof Error?n:new Error(String(n))}function w(n){return n instanceof DOMException&&n.name==="AbortError"}var ne="0.1.1";Object.defineProperty(exports,"CORE_VERSION",{enumerable:true,get:function(){return transferSdk.VERSION}});exports.REACT_SDK_VERSION=ne;exports.useStorageProfiles=K;exports.useTransferUpload=Q;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { StorageProfile, CreateTransferSessionOptions, ProgressEvent, Sha256ProgressEvent, ChunkDoneEvent, TransferSession, TransferSessionHandle } from '@rebalworks/transfer-sdk';
|
|
2
|
+
export { VERSION as CORE_VERSION, ChunkDoneEvent, CreateTransferSessionOptions, ProgressEvent, SessionCompleteEvent, SessionErrorEvent, Sha256ProgressEvent, StorageProfile, TransferSession, TransferSessionHandle } from '@rebalworks/transfer-sdk';
|
|
3
|
+
|
|
4
|
+
interface UseStorageProfilesOptions {
|
|
5
|
+
readonly apiRoot?: string | undefined;
|
|
6
|
+
readonly authToken?: string | undefined;
|
|
7
|
+
readonly enabled?: boolean | undefined;
|
|
8
|
+
}
|
|
9
|
+
interface StorageProfilesState {
|
|
10
|
+
readonly profiles: readonly StorageProfile[];
|
|
11
|
+
readonly defaultProfile?: StorageProfile | undefined;
|
|
12
|
+
readonly loading: boolean;
|
|
13
|
+
readonly error?: Error | undefined;
|
|
14
|
+
}
|
|
15
|
+
interface UseStorageProfilesResult extends StorageProfilesState {
|
|
16
|
+
readonly reload: () => Promise<readonly StorageProfile[]>;
|
|
17
|
+
}
|
|
18
|
+
declare function useStorageProfiles(options?: UseStorageProfilesOptions): UseStorageProfilesResult;
|
|
19
|
+
|
|
20
|
+
type TransferUploadPhase = 'idle' | 'hashing' | 'uploading' | 'completed' | 'aborted' | 'error';
|
|
21
|
+
type TransferUploadConfig = Omit<CreateTransferSessionOptions, 'file'> & {
|
|
22
|
+
readonly abortOnUnmount?: boolean | undefined;
|
|
23
|
+
};
|
|
24
|
+
type TransferUploadOverrides = Partial<Omit<CreateTransferSessionOptions, 'file'>>;
|
|
25
|
+
interface TransferUploadState {
|
|
26
|
+
readonly phase: TransferUploadPhase;
|
|
27
|
+
readonly progress?: ProgressEvent | undefined;
|
|
28
|
+
readonly sha256Progress?: Sha256ProgressEvent | undefined;
|
|
29
|
+
readonly lastChunk?: ChunkDoneEvent | undefined;
|
|
30
|
+
readonly session?: TransferSession | undefined;
|
|
31
|
+
readonly sessionId?: string | undefined;
|
|
32
|
+
readonly error?: Error | undefined;
|
|
33
|
+
}
|
|
34
|
+
interface UseTransferUploadResult extends TransferUploadState {
|
|
35
|
+
readonly uploading: boolean;
|
|
36
|
+
readonly completed: boolean;
|
|
37
|
+
readonly aborted: boolean;
|
|
38
|
+
readonly upload: (file: File, overrides?: TransferUploadOverrides) => TransferSessionHandle;
|
|
39
|
+
readonly abort: () => Promise<void>;
|
|
40
|
+
readonly reset: () => void;
|
|
41
|
+
readonly handle: TransferSessionHandle | null;
|
|
42
|
+
}
|
|
43
|
+
declare function useTransferUpload(config?: TransferUploadConfig): UseTransferUploadResult;
|
|
44
|
+
|
|
45
|
+
declare const REACT_SDK_VERSION = "0.1.1";
|
|
46
|
+
|
|
47
|
+
export { REACT_SDK_VERSION, type StorageProfilesState, type TransferUploadConfig, type TransferUploadOverrides, type TransferUploadPhase, type TransferUploadState, type UseStorageProfilesOptions, type UseStorageProfilesResult, type UseTransferUploadResult, useStorageProfiles, useTransferUpload };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { StorageProfile, CreateTransferSessionOptions, ProgressEvent, Sha256ProgressEvent, ChunkDoneEvent, TransferSession, TransferSessionHandle } from '@rebalworks/transfer-sdk';
|
|
2
|
+
export { VERSION as CORE_VERSION, ChunkDoneEvent, CreateTransferSessionOptions, ProgressEvent, SessionCompleteEvent, SessionErrorEvent, Sha256ProgressEvent, StorageProfile, TransferSession, TransferSessionHandle } from '@rebalworks/transfer-sdk';
|
|
3
|
+
|
|
4
|
+
interface UseStorageProfilesOptions {
|
|
5
|
+
readonly apiRoot?: string | undefined;
|
|
6
|
+
readonly authToken?: string | undefined;
|
|
7
|
+
readonly enabled?: boolean | undefined;
|
|
8
|
+
}
|
|
9
|
+
interface StorageProfilesState {
|
|
10
|
+
readonly profiles: readonly StorageProfile[];
|
|
11
|
+
readonly defaultProfile?: StorageProfile | undefined;
|
|
12
|
+
readonly loading: boolean;
|
|
13
|
+
readonly error?: Error | undefined;
|
|
14
|
+
}
|
|
15
|
+
interface UseStorageProfilesResult extends StorageProfilesState {
|
|
16
|
+
readonly reload: () => Promise<readonly StorageProfile[]>;
|
|
17
|
+
}
|
|
18
|
+
declare function useStorageProfiles(options?: UseStorageProfilesOptions): UseStorageProfilesResult;
|
|
19
|
+
|
|
20
|
+
type TransferUploadPhase = 'idle' | 'hashing' | 'uploading' | 'completed' | 'aborted' | 'error';
|
|
21
|
+
type TransferUploadConfig = Omit<CreateTransferSessionOptions, 'file'> & {
|
|
22
|
+
readonly abortOnUnmount?: boolean | undefined;
|
|
23
|
+
};
|
|
24
|
+
type TransferUploadOverrides = Partial<Omit<CreateTransferSessionOptions, 'file'>>;
|
|
25
|
+
interface TransferUploadState {
|
|
26
|
+
readonly phase: TransferUploadPhase;
|
|
27
|
+
readonly progress?: ProgressEvent | undefined;
|
|
28
|
+
readonly sha256Progress?: Sha256ProgressEvent | undefined;
|
|
29
|
+
readonly lastChunk?: ChunkDoneEvent | undefined;
|
|
30
|
+
readonly session?: TransferSession | undefined;
|
|
31
|
+
readonly sessionId?: string | undefined;
|
|
32
|
+
readonly error?: Error | undefined;
|
|
33
|
+
}
|
|
34
|
+
interface UseTransferUploadResult extends TransferUploadState {
|
|
35
|
+
readonly uploading: boolean;
|
|
36
|
+
readonly completed: boolean;
|
|
37
|
+
readonly aborted: boolean;
|
|
38
|
+
readonly upload: (file: File, overrides?: TransferUploadOverrides) => TransferSessionHandle;
|
|
39
|
+
readonly abort: () => Promise<void>;
|
|
40
|
+
readonly reset: () => void;
|
|
41
|
+
readonly handle: TransferSessionHandle | null;
|
|
42
|
+
}
|
|
43
|
+
declare function useTransferUpload(config?: TransferUploadConfig): UseTransferUploadResult;
|
|
44
|
+
|
|
45
|
+
declare const REACT_SDK_VERSION = "0.1.1";
|
|
46
|
+
|
|
47
|
+
export { REACT_SDK_VERSION, type StorageProfilesState, type TransferUploadConfig, type TransferUploadOverrides, type TransferUploadPhase, type TransferUploadState, type UseStorageProfilesOptions, type UseStorageProfilesResult, type UseTransferUploadResult, useStorageProfiles, useTransferUpload };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {useRef,useState,useCallback,useEffect}from'react';import {listStorageProfiles,createTransferSession}from'@rebalworks/transfer-sdk';export{VERSION as CORE_VERSION}from'@rebalworks/transfer-sdk';var V={profiles:[],loading:false};function K(n={}){let{apiRoot:r,authToken:p,enabled:T=true}=n,l=useRef(null),f=useRef(true),[E,S]=useState(V),g=useCallback(async()=>{l.current?.abort();let u=new AbortController;l.current=u,S(a=>({...a,loading:true,error:void 0}));try{let a=await listStorageProfiles({...r!==void 0?{apiRoot:r}:{},...p!==void 0?{authToken:p}:{},signal:u.signal}),d=a.find(t=>t.defaultProfile);return f.current&&l.current===u&&S({profiles:a,...d!==void 0?{defaultProfile:d}:{},loading:!1}),a}catch(a){let d=j(a);throw f.current&&l.current===u&&S(t=>({...t,loading:false,error:d})),d}},[r,p]);return useEffect(()=>(f.current=true,T&&g(),()=>{f.current=false,l.current?.abort();}),[T,g]),{...E,reload:g}}function j(n){return n instanceof Error?n:new Error(String(n))}var x={phase:"idle"};function Q(n={}){let{abortOnUnmount:r=false,apiBase:p,authToken:T,chunkSize:l,forceMainThread:f,retries:E,resumeSessionId:S,sha256:g,signal:u,storageProfile:a,workerPoolSize:d}=n,t=useRef(true),i=useRef(null),U=useRef(null),[y,h]=useState(x),s=useCallback(()=>{U.current?.(),U.current=null;},[]),z=useCallback((P,v={})=>{s();let k=W(P,{apiBase:p,authToken:T,chunkSize:l,forceMainThread:f,retries:E,resumeSessionId:S,sha256:g,signal:u,storageProfile:a,workerPoolSize:d,...v}),o=createTransferSession(k);i.current=o,h({phase:k.sha256===void 0&&!k.forceMainThread?"hashing":"uploading"});let H=[o.on("sha256:progress",e=>{m({phase:e.percent>=100?"uploading":"hashing",sha256Progress:e});}),o.on("progress",e=>{m({phase:"uploading",progress:e});}),o.on("chunk:done",e=>{m({phase:"uploading",lastChunk:e});}),o.on("session:complete",e=>{D(e);}),o.on("session:error",e=>{C(e.error,e.cancelled);})];return U.current=()=>{for(let e of H)e();},o.sessionId.then(e=>m({sessionId:e})).catch(e=>C(I(e),w(e))),o.done.then(e=>{m({phase:"completed",session:e});}).catch(e=>C(I(e),w(e))),o;function m(e){!t.current||i.current!==o||h(c=>({...c,...e,error:e.phase==="error"?e.error:c.error}));}function D(e){!t.current||i.current!==o||(s(),h(c=>({...c,phase:"completed",session:e.session,error:void 0})));}function C(e,c){!t.current||i.current!==o||(s(),h(N=>({...N,phase:c?"aborted":"error",error:c?void 0:e})));}},[p,T,l,s,f,E,S,g,u,a,d]),A=useCallback(async()=>{let P=i.current;P!==null&&(await P.abort(),t.current&&i.current===P&&(s(),h(v=>({...v,phase:"aborted",error:void 0}))));},[s]),M=useCallback(()=>{s(),i.current=null,h(x);},[s]);return useEffect(()=>(t.current=true,()=>{t.current=false,s(),r&&i.current?.abort();}),[r,s]),{...y,uploading:y.phase==="hashing"||y.phase==="uploading",completed:y.phase==="completed",aborted:y.phase==="aborted",upload:z,abort:A,reset:M,handle:i.current}}function W(n,r){return {file:n,...r.apiBase!==void 0?{apiBase:r.apiBase}:{},...r.authToken!==void 0?{authToken:r.authToken}:{},...r.chunkSize!==void 0?{chunkSize:r.chunkSize}:{},...r.forceMainThread!==void 0?{forceMainThread:r.forceMainThread}:{},...r.retries!==void 0?{retries:r.retries}:{},...r.resumeSessionId!==void 0?{resumeSessionId:r.resumeSessionId}:{},...r.sha256!==void 0?{sha256:r.sha256}:{},...r.signal!==void 0?{signal:r.signal}:{},...r.storageProfile!==void 0?{storageProfile:r.storageProfile}:{},...r.workerPoolSize!==void 0?{workerPoolSize:r.workerPoolSize}:{}}}function I(n){return n instanceof Error?n:new Error(String(n))}function w(n){return n instanceof DOMException&&n.name==="AbortError"}var ne="0.1.1";export{ne as REACT_SDK_VERSION,K as useStorageProfiles,Q as useTransferUpload};
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rebalworks/transfer-react",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "React hooks for rebalTransfer uploads",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
6
|
+
"private": false,
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.cjs",
|
|
9
|
+
"module": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"require": "./dist/index.cjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsup",
|
|
28
|
+
"typecheck": "tsc --noEmit",
|
|
29
|
+
"lint": "echo 'lint not configured'",
|
|
30
|
+
"test": "pnpm build && node --test test/*.test.mjs",
|
|
31
|
+
"clean": "rimraf dist"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@rebalworks/transfer-sdk": "workspace:*"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"react": ">=18"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/react": "^18.3.0",
|
|
41
|
+
"react": ">=18",
|
|
42
|
+
"rimraf": "^6.0.0",
|
|
43
|
+
"tsup": "^8.3.0",
|
|
44
|
+
"typescript": "^5.5.0"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=20"
|
|
48
|
+
}
|
|
49
|
+
}
|