@masters-union/union-stack 0.1.2

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,188 @@
1
+ type UploadErrorCode = 'NETWORK' | 'VALIDATION' | 'AUTH' | 'QUOTA' | 'ABORTED' | 'SERVER' | 'CONFIG' | 'PART_FAILED';
2
+ interface UploadError {
3
+ code: UploadErrorCode;
4
+ message: string;
5
+ status?: number;
6
+ /** True if a retry has a reasonable chance of succeeding. */
7
+ retryable: boolean;
8
+ /** Raw error from fetch / server (debugging only — don't display). */
9
+ cause?: unknown;
10
+ }
11
+ interface PickedFile {
12
+ uploadId: string;
13
+ filename: string;
14
+ mimetype: string;
15
+ size: number;
16
+ source: 'local' | 'url' | 'camera' | 'drop';
17
+ }
18
+ interface UploadedFile extends PickedFile {
19
+ /** Server-side file id — also stored as `handle` for Filestack compatibility. */
20
+ handle: string;
21
+ fileId: string;
22
+ url: string;
23
+ /** Object key in R2 (debugging only). */
24
+ key?: string;
25
+ status: 'Stored';
26
+ etag?: string;
27
+ uploadTags?: Record<string, string>;
28
+ }
29
+ interface ProgressEvent {
30
+ totalBytes: number;
31
+ loaded: number;
32
+ totalPercent: number;
33
+ }
34
+ interface PickResponse {
35
+ filesUploaded: UploadedFile[];
36
+ filesFailed: Array<{
37
+ file: PickedFile;
38
+ error: UploadError;
39
+ }>;
40
+ }
41
+ interface UploadOptions {
42
+ /** Override filename. Defaults to `file.name` when uploading a File. */
43
+ filename?: string;
44
+ /** Override mimeType. Defaults to `file.type` when uploading a File. */
45
+ mimeType?: string;
46
+ /** Arbitrary tags forwarded to the server and stored on the file record. */
47
+ metadata?: Record<string, unknown>;
48
+ /** Cancel an in-flight upload. */
49
+ signal?: AbortSignal;
50
+ /** How many part PUTs run in parallel. Defaults to 3. */
51
+ concurrency?: number;
52
+ /** Max retries per part. Defaults to 3. */
53
+ maxRetriesPerPart?: number;
54
+ onFileUploadStarted?: (file: PickedFile) => void;
55
+ onFileUploadProgress?: (file: PickedFile, ev: ProgressEvent) => void;
56
+ onFileUploadFinished?: (file: UploadedFile) => void;
57
+ onFileUploadFailed?: (file: PickedFile, error: UploadError) => void;
58
+ }
59
+ interface BatchUploadOptions extends UploadOptions {
60
+ /** Called once at the start of the batch with the file list. */
61
+ onUploadStarted?: (files: PickedFile[]) => void;
62
+ /** Terminal success — fires once even if some files failed (see `filesFailed`). */
63
+ onUploadDone?: (result: PickResponse) => void;
64
+ /** Terminal failure for the batch itself (auth, no network, ...). */
65
+ onError?: (error: UploadError) => void;
66
+ }
67
+ interface ClientConfig {
68
+ /** UnionStack API key, e.g. `unionstack_live_xxx`. */
69
+ apiKey: string;
70
+ /** Base URL of the cdn-be API. e.g. `https://api.unionstack.com/cdn-api` */
71
+ apiBase: string;
72
+ /** Override the upload chunk size in bytes (server may still cap this). */
73
+ chunkSize?: number;
74
+ /** Custom fetch impl — useful for testing / non-browser environments. */
75
+ fetch?: typeof fetch;
76
+ /**
77
+ * Disable auto-fetch of the picker config (`branding` + `theme`) when init()
78
+ * runs. Use when you only call `upload()` and never open the picker.
79
+ */
80
+ skipConfigPrefetch?: boolean;
81
+ }
82
+ /** Server-managed picker chrome + upload constraints fetched on init(). */
83
+ interface PickerConfig {
84
+ branding: {
85
+ logoUrl: string | null;
86
+ title: string | null;
87
+ hideFooter: boolean;
88
+ footerText: string | null;
89
+ };
90
+ theme: {
91
+ primary: string | null;
92
+ background: string | null;
93
+ foreground: string | null;
94
+ border: string | null;
95
+ radius: string | null;
96
+ mode: 'light' | 'dark' | null;
97
+ };
98
+ constraints: {
99
+ maxFileSizeBytes: number;
100
+ minFileSizeBytes: number;
101
+ maxFilesPerUpload: number;
102
+ chunkSizeBytes: number;
103
+ allowedMimeTypes: string[];
104
+ };
105
+ mode: 'live' | 'test';
106
+ }
107
+ type Source = PickedFile['source'];
108
+
109
+ interface PickerTheme {
110
+ /** Primary accent color (buttons, progress bar, focus rings). */
111
+ primary?: string;
112
+ /** Modal background. */
113
+ background?: string;
114
+ /** Default text color. */
115
+ foreground?: string;
116
+ /** Muted text (filenames, hints). */
117
+ muted?: string;
118
+ /** Border color for dropzone + cards. */
119
+ border?: string;
120
+ /** Border radius — accepts any CSS length. */
121
+ radius?: string;
122
+ /** Color mode hint — used to pick contrast-friendly defaults. */
123
+ mode?: 'light' | 'dark';
124
+ }
125
+ interface PickerBranding {
126
+ /** URL of a small logo to show in the modal header. */
127
+ logoUrl?: string;
128
+ /** Header title. Default: "Upload". */
129
+ title?: string;
130
+ /** Hide "Powered by UnionStack" footer. */
131
+ hideFooter?: boolean;
132
+ }
133
+ interface PickerOptions extends Omit<BatchUploadOptions, 'signal'> {
134
+ /** Constrain selectable files (HTML accept syntax). */
135
+ accept?: string;
136
+ /** Cap on file count selected at once. */
137
+ maxFiles?: number;
138
+ /** Max file size in bytes — additional client-side check before init. */
139
+ maxFileSize?: number;
140
+ theme?: PickerTheme;
141
+ branding?: PickerBranding;
142
+ /** Where to mount the modal. Default: document.body. */
143
+ container?: HTMLElement;
144
+ onOpen?: () => void;
145
+ onClose?: () => void;
146
+ onCancel?: () => void;
147
+ onFileSelected?: (file: PickedFile) => void | PickedFile | Promise<PickedFile | void>;
148
+ }
149
+ interface PickerHandle {
150
+ open(): Promise<PickResponse>;
151
+ close(): void;
152
+ cancel(): void;
153
+ }
154
+
155
+ interface PickerHandleLike {
156
+ open(): Promise<PickResponse>;
157
+ close(): void;
158
+ cancel(): void;
159
+ }
160
+ declare class UnionStackClient {
161
+ private cfg;
162
+ private uploader;
163
+ /**
164
+ * Promise that resolves to the server-managed picker config. Pre-fetched on
165
+ * construction (unless `skipConfigPrefetch: true`) so the picker opens
166
+ * without a network hit. Fails silently — picker falls back to defaults.
167
+ */
168
+ pickerConfigPromise: Promise<PickerConfig | null>;
169
+ constructor(cfg: ClientConfig);
170
+ /** Upload a single file. Mirrors Filestack's `client.upload()`. */
171
+ upload(file: File | Blob, opts?: UploadOptions): Promise<UploadedFile>;
172
+ /**
173
+ * Upload multiple files concurrently. Mirrors Filestack's batch behavior:
174
+ * onUploadDone fires once even if some files failed — failures land in
175
+ * `filesFailed`, successes in `filesUploaded`. `onError` is reserved for
176
+ * batch-level failures (no files even started).
177
+ */
178
+ uploadMany(files: (File | Blob)[], opts?: BatchUploadOptions): Promise<PickResponse>;
179
+ /**
180
+ * Open the file picker modal. Lazy-loads the picker bundle so the core
181
+ * SDK stays small for callers that only use `upload()` directly.
182
+ */
183
+ picker(opts?: PickerOptions): PickerHandleLike;
184
+ /** Read-only accessor used by the React/picker packages. */
185
+ get config(): Readonly<ClientConfig>;
186
+ }
187
+
188
+ export { type BatchUploadOptions as B, type ClientConfig as C, type PickResponse as P, type Source as S, UnionStackClient as U, type PickedFile as a, type ProgressEvent as b, type UploadError as c, type UploadErrorCode as d, type UploadOptions as e, type UploadedFile as f, type PickerOptions as g, type PickerHandle as h, type PickerBranding as i, type PickerTheme as j };
package/dist/index.cjs ADDED
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ var chunkQE2P5WH4_cjs = require('./chunk-QE2P5WH4.cjs');
4
+
5
+ // src/index.ts
6
+ var UnionStack = {
7
+ init(cfg) {
8
+ return new chunkQE2P5WH4_cjs.UnionStackClient(cfg);
9
+ }
10
+ };
11
+
12
+ Object.defineProperty(exports, "UnionStackClient", {
13
+ enumerable: true,
14
+ get: function () { return chunkQE2P5WH4_cjs.UnionStackClient; }
15
+ });
16
+ exports.UnionStack = UnionStack;
17
+ //# sourceMappingURL=index.cjs.map
18
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":["UnionStackClient"],"mappings":";;;;;AAaO,IAAM,UAAA,GAAa;AAAA,EACxB,KAAK,GAAA,EAAqC;AACxC,IAAA,OAAO,IAAIA,mCAAiB,GAAG,CAAA;AAAA,EACjC;AACF","file":"index.cjs","sourcesContent":["import { UnionStackClient } from './client.js';\nimport type { ClientConfig } from './types.js';\n\n/**\n * UnionStack — file upload SDK.\n *\n * import { UnionStack } from '@masters-union/union-stack';\n * const client = UnionStack.init({\n * apiKey: 'unionstack_live_…',\n * apiBase: 'https://api.unionstack.com/cdn-api',\n * });\n * const uploaded = await client.upload(file, { onFileUploadProgress: … });\n */\nexport const UnionStack = {\n init(cfg: ClientConfig): UnionStackClient {\n return new UnionStackClient(cfg);\n },\n};\n\nexport { UnionStackClient } from './client.js';\nexport type {\n ClientConfig,\n UploadOptions,\n BatchUploadOptions,\n PickedFile,\n UploadedFile,\n ProgressEvent,\n PickResponse,\n UploadError,\n UploadErrorCode,\n Source,\n} from './types.js';\n"]}
@@ -0,0 +1,18 @@
1
+ import { C as ClientConfig, U as UnionStackClient } from './client-xFfk4uu4.cjs';
2
+ export { B as BatchUploadOptions, P as PickResponse, a as PickedFile, b as ProgressEvent, S as Source, c as UploadError, d as UploadErrorCode, e as UploadOptions, f as UploadedFile } from './client-xFfk4uu4.cjs';
3
+
4
+ /**
5
+ * UnionStack — file upload SDK.
6
+ *
7
+ * import { UnionStack } from '@masters-union/union-stack';
8
+ * const client = UnionStack.init({
9
+ * apiKey: 'unionstack_live_…',
10
+ * apiBase: 'https://api.unionstack.com/cdn-api',
11
+ * });
12
+ * const uploaded = await client.upload(file, { onFileUploadProgress: … });
13
+ */
14
+ declare const UnionStack: {
15
+ init(cfg: ClientConfig): UnionStackClient;
16
+ };
17
+
18
+ export { ClientConfig, UnionStack, UnionStackClient };
@@ -0,0 +1,18 @@
1
+ import { C as ClientConfig, U as UnionStackClient } from './client-xFfk4uu4.js';
2
+ export { B as BatchUploadOptions, P as PickResponse, a as PickedFile, b as ProgressEvent, S as Source, c as UploadError, d as UploadErrorCode, e as UploadOptions, f as UploadedFile } from './client-xFfk4uu4.js';
3
+
4
+ /**
5
+ * UnionStack — file upload SDK.
6
+ *
7
+ * import { UnionStack } from '@masters-union/union-stack';
8
+ * const client = UnionStack.init({
9
+ * apiKey: 'unionstack_live_…',
10
+ * apiBase: 'https://api.unionstack.com/cdn-api',
11
+ * });
12
+ * const uploaded = await client.upload(file, { onFileUploadProgress: … });
13
+ */
14
+ declare const UnionStack: {
15
+ init(cfg: ClientConfig): UnionStackClient;
16
+ };
17
+
18
+ export { ClientConfig, UnionStack, UnionStackClient };
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ import { UnionStackClient } from './chunk-5Q2UADFS.js';
2
+ export { UnionStackClient } from './chunk-5Q2UADFS.js';
3
+
4
+ // src/index.ts
5
+ var UnionStack = {
6
+ init(cfg) {
7
+ return new UnionStackClient(cfg);
8
+ }
9
+ };
10
+
11
+ export { UnionStack };
12
+ //# sourceMappingURL=index.js.map
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;AAaO,IAAM,UAAA,GAAa;AAAA,EACxB,KAAK,GAAA,EAAqC;AACxC,IAAA,OAAO,IAAI,iBAAiB,GAAG,CAAA;AAAA,EACjC;AACF","file":"index.js","sourcesContent":["import { UnionStackClient } from './client.js';\nimport type { ClientConfig } from './types.js';\n\n/**\n * UnionStack — file upload SDK.\n *\n * import { UnionStack } from '@masters-union/union-stack';\n * const client = UnionStack.init({\n * apiKey: 'unionstack_live_…',\n * apiBase: 'https://api.unionstack.com/cdn-api',\n * });\n * const uploaded = await client.upload(file, { onFileUploadProgress: … });\n */\nexport const UnionStack = {\n init(cfg: ClientConfig): UnionStackClient {\n return new UnionStackClient(cfg);\n },\n};\n\nexport { UnionStackClient } from './client.js';\nexport type {\n ClientConfig,\n UploadOptions,\n BatchUploadOptions,\n PickedFile,\n UploadedFile,\n ProgressEvent,\n PickResponse,\n UploadError,\n UploadErrorCode,\n Source,\n} from './types.js';\n"]}