@autorender/sdk-core 0.1.21 → 0.1.23
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 +1 -0
- package/dist/index.cjs +94 -109
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +93 -109
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
package/dist/index.d.cts
CHANGED
|
@@ -99,6 +99,7 @@ interface UploadSettings {
|
|
|
99
99
|
pretransformations?: string;
|
|
100
100
|
tags?: string[];
|
|
101
101
|
is_unique_suffix_name?: boolean;
|
|
102
|
+
custom_id?: string;
|
|
102
103
|
}
|
|
103
104
|
type Environment = 'prod' | 'dev';
|
|
104
105
|
type Palette = 'at-blue' | 'at-purple' | 'at-red' | 'at-orange' | 'at-green' | 'at-turquoise' | 'at-gray';
|
|
@@ -336,6 +337,7 @@ interface LayerEnhancementOptions {
|
|
|
336
337
|
[key: string]: any;
|
|
337
338
|
}
|
|
338
339
|
interface ResponsiveOptions {
|
|
340
|
+
/** Workspace-relative asset path (e.g. `products/shoe.jpg`) or `https://...` / `http://...` for remote fetch via `fetch_` prefix. */
|
|
339
341
|
src: string;
|
|
340
342
|
width?: number;
|
|
341
343
|
sizes?: string;
|
|
@@ -356,6 +358,18 @@ interface ARInstance {
|
|
|
356
358
|
getConnectionQuality(): '2g' | '3g' | '4g' | 'wifi' | 'unknown';
|
|
357
359
|
}
|
|
358
360
|
|
|
361
|
+
/**
|
|
362
|
+
* URL builder for AutoRender image URLs
|
|
363
|
+
*/
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Workspace path segment for `ar.url()` / ARImage `src`.
|
|
367
|
+
*
|
|
368
|
+
* - Relative paths (`products/shoe.jpg`): each path segment is encoded separately.
|
|
369
|
+
* - Absolute URLs (`https://demo.com/photo.jpg`): emitted as `fetch_<url>`.
|
|
370
|
+
*/
|
|
371
|
+
declare function encodeAssetPathForDelivery(src: string): string;
|
|
372
|
+
|
|
359
373
|
/**
|
|
360
374
|
* Main AutoRender client factory
|
|
361
375
|
* Creates an AR instance with URL building and responsive image capabilities
|
|
@@ -386,4 +400,4 @@ declare function createUploader(options: CreateUploaderOptions): UploaderInstanc
|
|
|
386
400
|
|
|
387
401
|
declare function registerAutorenderUploaderElement(): void;
|
|
388
402
|
|
|
389
|
-
export { type ARInstance, type ApiFolderRequest, type AppRunnerResponse, type CompleteUploadPayload, type CompleteUploadResponse, type CreateARConfig, type CreateUploaderOptions, type Environment, type IconRenderer, type IconSet, type IngestErrorResponse, type IngestSuccessResponse, type LabelSet, type LayerEnhancementOptions, type LayerOptions, type Palette, type PresignPayload, type PresignResponse, type PresignedFile, type ResponsiveAttributes, type ResponsiveOptions, type ThemeOptions, type TransformOptions, type UploadItem, type UploadSettings, type UploadSourceOption, type UploadStatus, type UploadSuccessFile, type UploadedFileResponse, type UploaderClassNames, type UploaderInstance, createAR, createUploader, detectBestFormat, getBestFormatSync, registerAutorenderUploaderElement, resetFormatCache };
|
|
403
|
+
export { type ARInstance, type ApiFolderRequest, type AppRunnerResponse, type CompleteUploadPayload, type CompleteUploadResponse, type CreateARConfig, type CreateUploaderOptions, type Environment, type IconRenderer, type IconSet, type IngestErrorResponse, type IngestSuccessResponse, type LabelSet, type LayerEnhancementOptions, type LayerOptions, type Palette, type PresignPayload, type PresignResponse, type PresignedFile, type ResponsiveAttributes, type ResponsiveOptions, type ThemeOptions, type TransformOptions, type UploadItem, type UploadSettings, type UploadSourceOption, type UploadStatus, type UploadSuccessFile, type UploadedFileResponse, type UploaderClassNames, type UploaderInstance, createAR, createUploader, detectBestFormat, encodeAssetPathForDelivery, getBestFormatSync, registerAutorenderUploaderElement, resetFormatCache };
|
package/dist/index.d.ts
CHANGED
|
@@ -99,6 +99,7 @@ interface UploadSettings {
|
|
|
99
99
|
pretransformations?: string;
|
|
100
100
|
tags?: string[];
|
|
101
101
|
is_unique_suffix_name?: boolean;
|
|
102
|
+
custom_id?: string;
|
|
102
103
|
}
|
|
103
104
|
type Environment = 'prod' | 'dev';
|
|
104
105
|
type Palette = 'at-blue' | 'at-purple' | 'at-red' | 'at-orange' | 'at-green' | 'at-turquoise' | 'at-gray';
|
|
@@ -336,6 +337,7 @@ interface LayerEnhancementOptions {
|
|
|
336
337
|
[key: string]: any;
|
|
337
338
|
}
|
|
338
339
|
interface ResponsiveOptions {
|
|
340
|
+
/** Workspace-relative asset path (e.g. `products/shoe.jpg`) or `https://...` / `http://...` for remote fetch via `fetch_` prefix. */
|
|
339
341
|
src: string;
|
|
340
342
|
width?: number;
|
|
341
343
|
sizes?: string;
|
|
@@ -356,6 +358,18 @@ interface ARInstance {
|
|
|
356
358
|
getConnectionQuality(): '2g' | '3g' | '4g' | 'wifi' | 'unknown';
|
|
357
359
|
}
|
|
358
360
|
|
|
361
|
+
/**
|
|
362
|
+
* URL builder for AutoRender image URLs
|
|
363
|
+
*/
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Workspace path segment for `ar.url()` / ARImage `src`.
|
|
367
|
+
*
|
|
368
|
+
* - Relative paths (`products/shoe.jpg`): each path segment is encoded separately.
|
|
369
|
+
* - Absolute URLs (`https://demo.com/photo.jpg`): emitted as `fetch_<url>`.
|
|
370
|
+
*/
|
|
371
|
+
declare function encodeAssetPathForDelivery(src: string): string;
|
|
372
|
+
|
|
359
373
|
/**
|
|
360
374
|
* Main AutoRender client factory
|
|
361
375
|
* Creates an AR instance with URL building and responsive image capabilities
|
|
@@ -386,4 +400,4 @@ declare function createUploader(options: CreateUploaderOptions): UploaderInstanc
|
|
|
386
400
|
|
|
387
401
|
declare function registerAutorenderUploaderElement(): void;
|
|
388
402
|
|
|
389
|
-
export { type ARInstance, type ApiFolderRequest, type AppRunnerResponse, type CompleteUploadPayload, type CompleteUploadResponse, type CreateARConfig, type CreateUploaderOptions, type Environment, type IconRenderer, type IconSet, type IngestErrorResponse, type IngestSuccessResponse, type LabelSet, type LayerEnhancementOptions, type LayerOptions, type Palette, type PresignPayload, type PresignResponse, type PresignedFile, type ResponsiveAttributes, type ResponsiveOptions, type ThemeOptions, type TransformOptions, type UploadItem, type UploadSettings, type UploadSourceOption, type UploadStatus, type UploadSuccessFile, type UploadedFileResponse, type UploaderClassNames, type UploaderInstance, createAR, createUploader, detectBestFormat, getBestFormatSync, registerAutorenderUploaderElement, resetFormatCache };
|
|
403
|
+
export { type ARInstance, type ApiFolderRequest, type AppRunnerResponse, type CompleteUploadPayload, type CompleteUploadResponse, type CreateARConfig, type CreateUploaderOptions, type Environment, type IconRenderer, type IconSet, type IngestErrorResponse, type IngestSuccessResponse, type LabelSet, type LayerEnhancementOptions, type LayerOptions, type Palette, type PresignPayload, type PresignResponse, type PresignedFile, type ResponsiveAttributes, type ResponsiveOptions, type ThemeOptions, type TransformOptions, type UploadItem, type UploadSettings, type UploadSourceOption, type UploadStatus, type UploadSuccessFile, type UploadedFileResponse, type UploaderClassNames, type UploaderInstance, createAR, createUploader, detectBestFormat, encodeAssetPathForDelivery, getBestFormatSync, registerAutorenderUploaderElement, resetFormatCache };
|
package/dist/index.js
CHANGED
|
@@ -152,129 +152,86 @@ var AutorenderApiClient = class {
|
|
|
152
152
|
this.apiKey = opts.apiKey;
|
|
153
153
|
this.baseUrl = (opts.baseUrl || getBaseUrl(opts.environment || "prod")).replace(/\/+$/, "");
|
|
154
154
|
}
|
|
155
|
-
|
|
155
|
+
uploadFile(params, onProgress, signal) {
|
|
156
156
|
return new Promise((resolve, reject) => {
|
|
157
|
+
if (signal?.aborted) {
|
|
158
|
+
reject(new DOMException("Upload aborted", "AbortError"));
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
157
161
|
const xhr = new XMLHttpRequest();
|
|
162
|
+
if (signal) {
|
|
163
|
+
signal.addEventListener("abort", () => {
|
|
164
|
+
xhr.abort();
|
|
165
|
+
reject(new DOMException("Upload aborted", "AbortError"));
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
let lastProgress = 0;
|
|
169
|
+
xhr.upload.onprogress = (event) => {
|
|
170
|
+
if (event.lengthComputable && onProgress) {
|
|
171
|
+
const progress = Math.round(event.loaded / event.total * 100);
|
|
172
|
+
lastProgress = progress;
|
|
173
|
+
onProgress(progress);
|
|
174
|
+
} else if (onProgress && event.loaded > 0) {
|
|
175
|
+
const estimatedProgress = Math.min(
|
|
176
|
+
95,
|
|
177
|
+
Math.round(event.loaded / (event.loaded + 1e6) * 100)
|
|
178
|
+
);
|
|
179
|
+
if (estimatedProgress > lastProgress) {
|
|
180
|
+
lastProgress = estimatedProgress;
|
|
181
|
+
onProgress(estimatedProgress);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
};
|
|
158
185
|
xhr.onerror = () => {
|
|
159
|
-
reject(new Error(`
|
|
186
|
+
reject(new Error(`Upload failed: ${xhr.statusText}`));
|
|
160
187
|
};
|
|
161
188
|
xhr.onload = () => {
|
|
162
189
|
try {
|
|
163
190
|
if (xhr.status < 200 || xhr.status >= 300) {
|
|
164
191
|
const errorText = xhr.responseText || xhr.statusText;
|
|
165
|
-
reject(new Error(`
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
const response = JSON.parse(xhr.responseText);
|
|
169
|
-
if (!response.token) {
|
|
170
|
-
reject(new Error("Token not found in response"));
|
|
192
|
+
reject(new Error(`Upload failed: ${errorText}`));
|
|
171
193
|
return;
|
|
172
194
|
}
|
|
173
|
-
|
|
195
|
+
const newResponse = JSON.parse(xhr.responseText);
|
|
196
|
+
const response = {
|
|
197
|
+
success: true,
|
|
198
|
+
file_no: newResponse.file_no || newResponse.id,
|
|
199
|
+
name: newResponse.name,
|
|
200
|
+
url: newResponse.url,
|
|
201
|
+
file_size: newResponse.size,
|
|
202
|
+
format: newResponse.format,
|
|
203
|
+
width: newResponse.width,
|
|
204
|
+
height: newResponse.height,
|
|
205
|
+
created_at: newResponse.created_at,
|
|
206
|
+
path: newResponse.path,
|
|
207
|
+
workspace_no: newResponse.workspace_id,
|
|
208
|
+
isDuplicate: newResponse.is_duplicate || false
|
|
209
|
+
};
|
|
210
|
+
resolve(response);
|
|
174
211
|
} catch (error) {
|
|
175
|
-
reject(new Error("Failed to parse
|
|
212
|
+
reject(new Error("Failed to parse response"));
|
|
176
213
|
}
|
|
177
214
|
};
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
215
|
+
const endpoint = `${this.baseUrl}/uploads`;
|
|
216
|
+
const formData = new FormData();
|
|
217
|
+
formData.append("file", params.file);
|
|
218
|
+
formData.append("file_name", params.file.name);
|
|
219
|
+
if (params.folderPath) {
|
|
220
|
+
formData.append("folder", params.folderPath);
|
|
181
221
|
}
|
|
182
|
-
if (
|
|
183
|
-
|
|
222
|
+
if (params.settings?.tags?.length) {
|
|
223
|
+
formData.append("tags", params.settings.tags.join(","));
|
|
224
|
+
}
|
|
225
|
+
if (params.settings?.pretransformations) {
|
|
226
|
+
formData.append("transform", params.settings.pretransformations);
|
|
227
|
+
}
|
|
228
|
+
if (params.settings?.custom_id) {
|
|
229
|
+
formData.append("custom_id", params.settings.custom_id);
|
|
184
230
|
}
|
|
185
|
-
const tokenRequest = {
|
|
186
|
-
file_name: params.file.name,
|
|
187
|
-
...folder && { folder },
|
|
188
|
-
...params.settings?.tags && { tags: params.settings.tags },
|
|
189
|
-
...params.settings?.pretransformations && { transform: params.settings.pretransformations },
|
|
190
|
-
max_file_size: params.file.size,
|
|
191
|
-
allow_override: {
|
|
192
|
-
folder: true,
|
|
193
|
-
tags: true,
|
|
194
|
-
transform: true
|
|
195
|
-
},
|
|
196
|
-
random_prefix: !params.settings?.is_unique_suffix_name
|
|
197
|
-
};
|
|
198
|
-
const endpoint = `${this.baseUrl}/generate-token`;
|
|
199
231
|
xhr.open("POST", endpoint);
|
|
200
232
|
xhr.setRequestHeader("Authorization", `Bearer ${this.apiKey}`);
|
|
201
|
-
xhr.setRequestHeader("Content-Type", "application/json");
|
|
202
233
|
xhr.setRequestHeader("accept", "application/json");
|
|
203
|
-
xhr.send(
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
uploadFile(params, onProgress, signal) {
|
|
207
|
-
return new Promise(async (resolve, reject) => {
|
|
208
|
-
if (signal?.aborted) {
|
|
209
|
-
reject(new DOMException("Upload aborted", "AbortError"));
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
try {
|
|
213
|
-
const token = await this.generateToken(params);
|
|
214
|
-
if (signal?.aborted) {
|
|
215
|
-
reject(new DOMException("Upload aborted", "AbortError"));
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
const xhr = new XMLHttpRequest();
|
|
219
|
-
if (signal) {
|
|
220
|
-
signal.addEventListener("abort", () => {
|
|
221
|
-
xhr.abort();
|
|
222
|
-
reject(new DOMException("Upload aborted", "AbortError"));
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
let lastProgress = 0;
|
|
226
|
-
xhr.upload.onprogress = (event) => {
|
|
227
|
-
if (event.lengthComputable && onProgress) {
|
|
228
|
-
const progress = Math.round(event.loaded / event.total * 100);
|
|
229
|
-
lastProgress = progress;
|
|
230
|
-
onProgress(progress);
|
|
231
|
-
} else if (onProgress && event.loaded > 0) {
|
|
232
|
-
const estimatedProgress = Math.min(95, Math.round(event.loaded / (event.loaded + 1e6) * 100));
|
|
233
|
-
if (estimatedProgress > lastProgress) {
|
|
234
|
-
lastProgress = estimatedProgress;
|
|
235
|
-
onProgress(estimatedProgress);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
xhr.onerror = () => {
|
|
240
|
-
reject(new Error(`Upload failed: ${xhr.statusText}`));
|
|
241
|
-
};
|
|
242
|
-
xhr.onload = () => {
|
|
243
|
-
try {
|
|
244
|
-
if (xhr.status < 200 || xhr.status >= 300) {
|
|
245
|
-
const errorText = xhr.responseText || xhr.statusText;
|
|
246
|
-
reject(new Error(`Upload failed: ${errorText}`));
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
const newResponse = JSON.parse(xhr.responseText);
|
|
250
|
-
const response = {
|
|
251
|
-
success: true,
|
|
252
|
-
file_no: newResponse.file_no || newResponse.id,
|
|
253
|
-
name: newResponse.name,
|
|
254
|
-
url: newResponse.url,
|
|
255
|
-
file_size: newResponse.size,
|
|
256
|
-
format: newResponse.format,
|
|
257
|
-
width: newResponse.width,
|
|
258
|
-
height: newResponse.height,
|
|
259
|
-
created_at: newResponse.created_at,
|
|
260
|
-
path: newResponse.path,
|
|
261
|
-
workspace_no: newResponse.workspace_id,
|
|
262
|
-
isDuplicate: newResponse.is_duplicate || false
|
|
263
|
-
};
|
|
264
|
-
resolve(response);
|
|
265
|
-
} catch (error) {
|
|
266
|
-
reject(new Error("Failed to parse response"));
|
|
267
|
-
}
|
|
268
|
-
};
|
|
269
|
-
const endpoint = `${this.baseUrl}/uploads/${token}`;
|
|
270
|
-
xhr.open("POST", endpoint);
|
|
271
|
-
xhr.setRequestHeader("accept", "application/json");
|
|
272
|
-
const mimeType = params.file.type || "application/octet-stream";
|
|
273
|
-
xhr.setRequestHeader("Content-Type", mimeType);
|
|
274
|
-
xhr.send(params.file);
|
|
275
|
-
} catch (error) {
|
|
276
|
-
reject(error);
|
|
277
|
-
}
|
|
234
|
+
xhr.send(formData);
|
|
278
235
|
});
|
|
279
236
|
}
|
|
280
237
|
};
|
|
@@ -677,7 +634,8 @@ var UploaderController = class extends EventTarget {
|
|
|
677
634
|
settings: uploadSettings ? {
|
|
678
635
|
pretransformations: uploadSettings.pretransformations,
|
|
679
636
|
tags: uploadSettings.tags,
|
|
680
|
-
is_unique_suffix_name: uploadSettings.is_unique_suffix_name ?? false
|
|
637
|
+
is_unique_suffix_name: uploadSettings.is_unique_suffix_name ?? false,
|
|
638
|
+
custom_id: uploadSettings.custom_id
|
|
681
639
|
} : void 0
|
|
682
640
|
},
|
|
683
641
|
(progress) => {
|
|
@@ -3545,15 +3503,40 @@ function normalizePlacement(placement) {
|
|
|
3545
3503
|
}
|
|
3546
3504
|
|
|
3547
3505
|
// src/viewtag/url-builder.ts
|
|
3506
|
+
var ABSOLUTE_URL_RE = /^https?:\/\//i;
|
|
3507
|
+
function encodeAssetPathForDelivery(src) {
|
|
3508
|
+
const trimmed = src.trim();
|
|
3509
|
+
if (!trimmed) {
|
|
3510
|
+
return "";
|
|
3511
|
+
}
|
|
3512
|
+
if (ABSOLUTE_URL_RE.test(trimmed)) {
|
|
3513
|
+
const fetchPayload = `fetch_${trimmed}`;
|
|
3514
|
+
return encodeURIComponent(fetchPayload);
|
|
3515
|
+
}
|
|
3516
|
+
if (trimmed.startsWith("fetch_")) {
|
|
3517
|
+
return encodeURIComponent(trimmed);
|
|
3518
|
+
}
|
|
3519
|
+
return trimmed.split("/").filter(Boolean).map((segment) => encodeURIComponent(segment)).join("/");
|
|
3520
|
+
}
|
|
3548
3521
|
function buildImageUrl(baseUrl, workspace, src, transform, defaults, enableDPR = true, connectionQuality) {
|
|
3549
3522
|
const normalizedBase = baseUrl.replace(/\/+$/, "");
|
|
3550
3523
|
const transformStr = buildTransformString(transform || {}, defaults, enableDPR, connectionQuality);
|
|
3551
|
-
const
|
|
3524
|
+
const trimmedSrc = src.trim();
|
|
3525
|
+
if (ABSOLUTE_URL_RE.test(trimmedSrc)) {
|
|
3526
|
+
const fetchPart = `fetch_${trimmedSrc}`;
|
|
3527
|
+
const transformWithFetch = transformStr ? `${transformStr},${fetchPart}` : fetchPart;
|
|
3528
|
+
return `${normalizedBase}/${workspace}/${transformWithFetch}`;
|
|
3529
|
+
}
|
|
3530
|
+
if (trimmedSrc.startsWith("fetch_")) {
|
|
3531
|
+
const fetchPart = trimmedSrc;
|
|
3532
|
+
const transformWithFetch = transformStr ? `${transformStr},${fetchPart}` : fetchPart;
|
|
3533
|
+
return `${normalizedBase}/${workspace}/${transformWithFetch}`;
|
|
3534
|
+
}
|
|
3535
|
+
const encodedPath = encodeAssetPathForDelivery(trimmedSrc);
|
|
3552
3536
|
if (transformStr) {
|
|
3553
3537
|
return `${normalizedBase}/${workspace}/${transformStr}/${encodedPath}`;
|
|
3554
|
-
} else {
|
|
3555
|
-
return `${normalizedBase}/${workspace}/${encodedPath}`;
|
|
3556
3538
|
}
|
|
3539
|
+
return `${normalizedBase}/${workspace}/${encodedPath}`;
|
|
3557
3540
|
}
|
|
3558
3541
|
|
|
3559
3542
|
// src/viewtag/responsive.ts
|
|
@@ -3935,6 +3918,7 @@ export {
|
|
|
3935
3918
|
createAR,
|
|
3936
3919
|
createUploader,
|
|
3937
3920
|
detectBestFormat,
|
|
3921
|
+
encodeAssetPathForDelivery,
|
|
3938
3922
|
getBestFormatSync,
|
|
3939
3923
|
registerAutorenderUploaderElement,
|
|
3940
3924
|
resetFormatCache
|