@buildcores/render-client 1.5.0 → 1.7.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/README.md +34 -0
- package/dist/api.d.ts +2 -1
- package/dist/hooks/useSpriteRender.d.ts +10 -0
- package/dist/hooks/useZoomPan.d.ts +2 -1
- package/dist/index.d.ts +146 -2
- package/dist/index.esm.js +169 -47
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +169 -47
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +120 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -45,6 +45,33 @@ function App() {
|
|
|
45
45
|
}
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
+
## 🔐 Authentication Modes
|
|
49
|
+
|
|
50
|
+
`@buildcores/render-client` supports two auth modes:
|
|
51
|
+
|
|
52
|
+
- `legacy` (backward-compatible): sends a long-lived API key from `apiConfig.authToken`.
|
|
53
|
+
- `session` (recommended): fetches short-lived delegated tokens from your backend via `apiConfig.getRenderSessionToken`.
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
const apiConfig = {
|
|
57
|
+
environment: "prod",
|
|
58
|
+
authMode: "session",
|
|
59
|
+
getRenderSessionToken: async () => {
|
|
60
|
+
// Your backend endpoint should broker BuildCores /auth/render-session
|
|
61
|
+
const res = await fetch("/buildcores/session", { method: "POST" });
|
|
62
|
+
if (!res.ok) throw new Error("Failed to mint BuildCores session");
|
|
63
|
+
const data = await res.json();
|
|
64
|
+
return {
|
|
65
|
+
token: data.session_token,
|
|
66
|
+
expiresAt: data.expires_at,
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Legacy browser API key flow is deprecated and should only be used for temporary compatibility.
|
|
73
|
+
`/render-build-experimental` behavior is unchanged.
|
|
74
|
+
|
|
48
75
|
## 🔧 API Reference
|
|
49
76
|
|
|
50
77
|
### `BuildRender` Component
|
|
@@ -72,6 +99,11 @@ interface RenderBuildRequest {
|
|
|
72
99
|
format?: "video" | "sprite";
|
|
73
100
|
width?: number; // Optional: Canvas pixel width (256-2000)
|
|
74
101
|
height?: number; // Optional: Canvas pixel height (256-2000)
|
|
102
|
+
scene?: "sunset" | "dawn" | "night" | "warehouse" | "forest" | "apartment" | "studio" | "studio_v2" | "city" | "park" | "lobby";
|
|
103
|
+
showBackground?: boolean;
|
|
104
|
+
showGrid?: boolean;
|
|
105
|
+
winterMode?: boolean; // mutually exclusive with springMode
|
|
106
|
+
springMode?: boolean; // mutually exclusive with winterMode
|
|
75
107
|
}
|
|
76
108
|
|
|
77
109
|
// Available part categories
|
|
@@ -91,6 +123,8 @@ enum PartCategory {
|
|
|
91
123
|
|
|
92
124
|
**Resolution Control**: You can specify custom `width` and `height` (both must be provided together, 256-2000 pixels) for higher or lower quality renders. If not specified, the default resolution is used.
|
|
93
125
|
|
|
126
|
+
**Environment Controls**: You can configure `scene`, `showBackground`, `showGrid`, and seasonal toggles (`winterMode` / `springMode`) for async render endpoints.
|
|
127
|
+
|
|
94
128
|
#### Examples
|
|
95
129
|
|
|
96
130
|
**Complete Build (All Components)**
|
package/dist/api.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export interface RenderJobStatusResponse {
|
|
|
32
32
|
url?: string | null;
|
|
33
33
|
video_url?: string | null;
|
|
34
34
|
sprite_url?: string | null;
|
|
35
|
+
screenshot_url?: string | null;
|
|
35
36
|
error?: string | null;
|
|
36
37
|
end_time?: string | null;
|
|
37
38
|
}
|
|
@@ -71,7 +72,7 @@ export interface RenderAPIService {
|
|
|
71
72
|
getAvailableParts(category: PartCategory, config: ApiConfig, options?: GetAvailablePartsOptions): Promise<AvailablePartsResponse>;
|
|
72
73
|
}
|
|
73
74
|
export declare const buildApiUrl: (endpoint: string, config: ApiConfig) => string;
|
|
74
|
-
export declare const buildHeaders: (config: ApiConfig) => Record<string, string>;
|
|
75
|
+
export declare const buildHeaders: (config: ApiConfig, authTokenOverride?: string) => Record<string, string>;
|
|
75
76
|
export declare const renderBuildExperimental: (request: RenderBuildRequest, config: ApiConfig) => Promise<RenderBuildResponse>;
|
|
76
77
|
export declare const createRenderBuildJob: (request: RenderBuildRequest, config: ApiConfig) => Promise<RenderJobCreateResponse>;
|
|
77
78
|
export declare const getRenderBuildStatus: (jobId: string, config: ApiConfig) => Promise<RenderJobStatusResponse>;
|
|
@@ -34,7 +34,12 @@ export type SpriteRenderInput = {
|
|
|
34
34
|
type: 'parts';
|
|
35
35
|
parts: RenderBuildRequest;
|
|
36
36
|
showGrid?: boolean;
|
|
37
|
+
scene?: RenderBuildRequest["scene"];
|
|
38
|
+
showBackground?: boolean;
|
|
39
|
+
winterMode?: boolean;
|
|
40
|
+
springMode?: boolean;
|
|
37
41
|
cameraOffsetX?: number;
|
|
42
|
+
cameraZoom?: number;
|
|
38
43
|
gridSettings?: RenderGridSettings;
|
|
39
44
|
frameQuality?: 'standard' | 'high';
|
|
40
45
|
} | {
|
|
@@ -42,7 +47,12 @@ export type SpriteRenderInput = {
|
|
|
42
47
|
shareCode: string;
|
|
43
48
|
profile?: 'cinematic' | 'flat' | 'fast';
|
|
44
49
|
showGrid?: boolean;
|
|
50
|
+
scene?: RenderBuildRequest["scene"];
|
|
51
|
+
showBackground?: boolean;
|
|
52
|
+
winterMode?: boolean;
|
|
53
|
+
springMode?: boolean;
|
|
45
54
|
cameraOffsetX?: number;
|
|
55
|
+
cameraZoom?: number;
|
|
46
56
|
gridSettings?: RenderGridSettings;
|
|
47
57
|
frameQuality?: 'standard' | 'high';
|
|
48
58
|
};
|
|
@@ -4,6 +4,7 @@ interface UseZoomOptions {
|
|
|
4
4
|
displayHeight?: number;
|
|
5
5
|
minScale?: number;
|
|
6
6
|
maxScale?: number;
|
|
7
|
+
initialScale?: number;
|
|
7
8
|
}
|
|
8
9
|
interface UseZoomReturn {
|
|
9
10
|
scale: number;
|
|
@@ -12,5 +13,5 @@ interface UseZoomReturn {
|
|
|
12
13
|
handleTouchStart: (event: ReactTouchEvent<HTMLCanvasElement>) => boolean;
|
|
13
14
|
reset: () => void;
|
|
14
15
|
}
|
|
15
|
-
export declare const useZoomPan: ({ displayWidth, displayHeight, minScale, maxScale, }?: UseZoomOptions) => UseZoomReturn;
|
|
16
|
+
export declare const useZoomPan: ({ displayWidth, displayHeight, minScale, maxScale, initialScale, }?: UseZoomOptions) => UseZoomReturn;
|
|
16
17
|
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -229,6 +229,24 @@ interface BuildRenderProps {
|
|
|
229
229
|
* Works for both parts and shareCode rendering.
|
|
230
230
|
*/
|
|
231
231
|
showGrid?: boolean;
|
|
232
|
+
/**
|
|
233
|
+
* Environment scene preset for rendering.
|
|
234
|
+
*/
|
|
235
|
+
scene?: RenderScene;
|
|
236
|
+
/**
|
|
237
|
+
* Whether to show the environment background.
|
|
238
|
+
*/
|
|
239
|
+
showBackground?: boolean;
|
|
240
|
+
/**
|
|
241
|
+
* Enable winter mode effects.
|
|
242
|
+
* Mutually exclusive with springMode.
|
|
243
|
+
*/
|
|
244
|
+
winterMode?: boolean;
|
|
245
|
+
/**
|
|
246
|
+
* Enable spring mode effects.
|
|
247
|
+
* Mutually exclusive with winterMode.
|
|
248
|
+
*/
|
|
249
|
+
springMode?: boolean;
|
|
232
250
|
/**
|
|
233
251
|
* Camera offset X for composition.
|
|
234
252
|
* Positive values shift the build to the right, leaving room for text overlay on the left.
|
|
@@ -315,6 +333,46 @@ interface BuildRenderProps {
|
|
|
315
333
|
* @default "standard"
|
|
316
334
|
*/
|
|
317
335
|
frameQuality?: 'standard' | 'high';
|
|
336
|
+
/**
|
|
337
|
+
* Initial zoom level for the build.
|
|
338
|
+
* Range: 0.5 (50%) to 2.5 (250%). Values less than 1 make the build appear smaller,
|
|
339
|
+
* values greater than 1 make it appear larger.
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```tsx
|
|
343
|
+
* <BuildRender
|
|
344
|
+
* shareCode="abc123"
|
|
345
|
+
* zoom={0.7} // 70% size - build appears smaller
|
|
346
|
+
* />
|
|
347
|
+
*
|
|
348
|
+
* <BuildRender
|
|
349
|
+
* shareCode="abc123"
|
|
350
|
+
* zoom={1.5} // 150% size - build appears larger
|
|
351
|
+
* />
|
|
352
|
+
* ```
|
|
353
|
+
*
|
|
354
|
+
* @default 1
|
|
355
|
+
*/
|
|
356
|
+
zoom?: number;
|
|
357
|
+
/**
|
|
358
|
+
* Camera zoom level for server-side rendering.
|
|
359
|
+
* Values > 1 move the camera further away (build appears smaller in the sprite).
|
|
360
|
+
* Values < 1 move the camera closer (build appears larger in the sprite).
|
|
361
|
+
*
|
|
362
|
+
* Use this for higher quality scaled-down renders vs client-side zoom scaling.
|
|
363
|
+
* Range: 0.5 to 2.0
|
|
364
|
+
*
|
|
365
|
+
* @example
|
|
366
|
+
* ```tsx
|
|
367
|
+
* <BuildRender
|
|
368
|
+
* shareCode="abc123"
|
|
369
|
+
* cameraZoom={1.3} // Camera 30% further away - smaller build in sprite
|
|
370
|
+
* />
|
|
371
|
+
* ```
|
|
372
|
+
*
|
|
373
|
+
* @default 1
|
|
374
|
+
*/
|
|
375
|
+
cameraZoom?: number;
|
|
318
376
|
}
|
|
319
377
|
/**
|
|
320
378
|
* API configuration for environment and authentication
|
|
@@ -346,6 +404,22 @@ interface ApiConfig {
|
|
|
346
404
|
* ```
|
|
347
405
|
*/
|
|
348
406
|
authToken?: string;
|
|
407
|
+
/**
|
|
408
|
+
* Auth mode for API requests.
|
|
409
|
+
* - legacy: Sends `authToken` directly as bearer token.
|
|
410
|
+
* - session: Uses `getRenderSessionToken` to fetch short-lived delegated tokens.
|
|
411
|
+
*
|
|
412
|
+
* @default "legacy"
|
|
413
|
+
*/
|
|
414
|
+
authMode?: 'legacy' | 'session';
|
|
415
|
+
/**
|
|
416
|
+
* Session token supplier used when `authMode` is "session".
|
|
417
|
+
* Should call your backend endpoint that brokers BuildCores session tokens.
|
|
418
|
+
*/
|
|
419
|
+
getRenderSessionToken?: () => Promise<{
|
|
420
|
+
token: string;
|
|
421
|
+
expiresAt: string;
|
|
422
|
+
}>;
|
|
349
423
|
}
|
|
350
424
|
/**
|
|
351
425
|
* Enum defining all available PC part categories that can be rendered.
|
|
@@ -512,6 +586,24 @@ interface RenderBuildRequest {
|
|
|
512
586
|
* Defaults to true for cinematic profile, false otherwise.
|
|
513
587
|
*/
|
|
514
588
|
showGrid?: boolean;
|
|
589
|
+
/**
|
|
590
|
+
* Environment scene preset.
|
|
591
|
+
*/
|
|
592
|
+
scene?: RenderScene;
|
|
593
|
+
/**
|
|
594
|
+
* Whether to show the environment background.
|
|
595
|
+
*/
|
|
596
|
+
showBackground?: boolean;
|
|
597
|
+
/**
|
|
598
|
+
* Enable winter mode effects.
|
|
599
|
+
* Mutually exclusive with springMode.
|
|
600
|
+
*/
|
|
601
|
+
winterMode?: boolean;
|
|
602
|
+
/**
|
|
603
|
+
* Enable spring mode effects.
|
|
604
|
+
* Mutually exclusive with winterMode.
|
|
605
|
+
*/
|
|
606
|
+
springMode?: boolean;
|
|
515
607
|
/**
|
|
516
608
|
* Horizontal offset for the camera view.
|
|
517
609
|
* Positive values shift the build to the right, leaving room for text overlay on the left.
|
|
@@ -531,6 +623,15 @@ interface RenderBuildRequest {
|
|
|
531
623
|
* @default "standard"
|
|
532
624
|
*/
|
|
533
625
|
frameQuality?: 'standard' | 'high';
|
|
626
|
+
/**
|
|
627
|
+
* Camera zoom level for server-side rendering.
|
|
628
|
+
* Values > 1 move the camera further away (build appears smaller in the sprite).
|
|
629
|
+
* Values < 1 move the camera closer (build appears larger in the sprite).
|
|
630
|
+
* Range: 0.5 to 2.0
|
|
631
|
+
*
|
|
632
|
+
* @default 1
|
|
633
|
+
*/
|
|
634
|
+
cameraZoom?: number;
|
|
534
635
|
}
|
|
535
636
|
/**
|
|
536
637
|
* Response structure containing all available parts for each category.
|
|
@@ -674,6 +775,11 @@ interface BuildResponse {
|
|
|
674
775
|
partDetails: {
|
|
675
776
|
[K in PartCategory]?: PartDetailsWithCategory[];
|
|
676
777
|
};
|
|
778
|
+
/**
|
|
779
|
+
* Whether the case in this build has an interactive 3D model available.
|
|
780
|
+
* If false, the build cannot be rendered in 3D.
|
|
781
|
+
*/
|
|
782
|
+
hasInteractiveModel: boolean;
|
|
677
783
|
}
|
|
678
784
|
/**
|
|
679
785
|
* Response from the get parts by IDs endpoint.
|
|
@@ -705,6 +811,10 @@ interface GridSettings {
|
|
|
705
811
|
/** Render order for depth sorting (default: 0, use -1 to render before other objects) */
|
|
706
812
|
renderOrder?: number;
|
|
707
813
|
}
|
|
814
|
+
/**
|
|
815
|
+
* Supported environment scene presets for render API endpoints.
|
|
816
|
+
*/
|
|
817
|
+
type RenderScene = "sunset" | "dawn" | "night" | "warehouse" | "forest" | "apartment" | "studio" | "studio_v2" | "city" | "park" | "lobby";
|
|
708
818
|
/**
|
|
709
819
|
* Options for rendering a build by share code
|
|
710
820
|
*/
|
|
@@ -717,14 +827,24 @@ interface RenderByShareCodeOptions {
|
|
|
717
827
|
height?: number;
|
|
718
828
|
/** Render quality profile */
|
|
719
829
|
profile?: "cinematic" | "flat" | "fast";
|
|
830
|
+
/** Environment scene preset */
|
|
831
|
+
scene?: RenderScene;
|
|
832
|
+
/** Whether to show the environment background */
|
|
833
|
+
showBackground?: boolean;
|
|
720
834
|
/** Show grid in render (default: true for cinematic profile) */
|
|
721
835
|
showGrid?: boolean;
|
|
836
|
+
/** Enable winter mode effects (mutually exclusive with springMode) */
|
|
837
|
+
winterMode?: boolean;
|
|
838
|
+
/** Enable spring mode effects (mutually exclusive with winterMode) */
|
|
839
|
+
springMode?: boolean;
|
|
722
840
|
/** Camera offset X for composition (positive = shift build right to leave room for text overlay) */
|
|
723
841
|
cameraOffsetX?: number;
|
|
724
842
|
/** Grid appearance settings (for thicker/more visible grid in renders) */
|
|
725
843
|
gridSettings?: GridSettings;
|
|
726
844
|
/** Frame quality - 'standard' (72 frames) or 'high' (144 frames for smoother animation) */
|
|
727
845
|
frameQuality?: 'standard' | 'high';
|
|
846
|
+
/** Camera zoom level for rendering. Values > 1 move camera further (build appears smaller). Range: 0.5 to 2.0 */
|
|
847
|
+
cameraZoom?: number;
|
|
728
848
|
/** Polling interval in milliseconds (default: 1500) */
|
|
729
849
|
pollIntervalMs?: number;
|
|
730
850
|
/** Timeout in milliseconds (default: 120000 = 2 minutes) */
|
|
@@ -866,7 +986,12 @@ type SpriteRenderInput = {
|
|
|
866
986
|
type: 'parts';
|
|
867
987
|
parts: RenderBuildRequest;
|
|
868
988
|
showGrid?: boolean;
|
|
989
|
+
scene?: RenderBuildRequest["scene"];
|
|
990
|
+
showBackground?: boolean;
|
|
991
|
+
winterMode?: boolean;
|
|
992
|
+
springMode?: boolean;
|
|
869
993
|
cameraOffsetX?: number;
|
|
994
|
+
cameraZoom?: number;
|
|
870
995
|
gridSettings?: RenderGridSettings;
|
|
871
996
|
frameQuality?: 'standard' | 'high';
|
|
872
997
|
} | {
|
|
@@ -874,7 +999,12 @@ type SpriteRenderInput = {
|
|
|
874
999
|
shareCode: string;
|
|
875
1000
|
profile?: 'cinematic' | 'flat' | 'fast';
|
|
876
1001
|
showGrid?: boolean;
|
|
1002
|
+
scene?: RenderBuildRequest["scene"];
|
|
1003
|
+
showBackground?: boolean;
|
|
1004
|
+
winterMode?: boolean;
|
|
1005
|
+
springMode?: boolean;
|
|
877
1006
|
cameraOffsetX?: number;
|
|
1007
|
+
cameraZoom?: number;
|
|
878
1008
|
gridSettings?: RenderGridSettings;
|
|
879
1009
|
frameQuality?: 'standard' | 'high';
|
|
880
1010
|
};
|
|
@@ -925,6 +1055,20 @@ interface RenderBuildResponse {
|
|
|
925
1055
|
format?: string;
|
|
926
1056
|
};
|
|
927
1057
|
}
|
|
1058
|
+
interface RenderJobCreateResponse {
|
|
1059
|
+
job_id: string;
|
|
1060
|
+
status: "queued" | "processing" | "completed" | "error";
|
|
1061
|
+
}
|
|
1062
|
+
interface RenderJobStatusResponse {
|
|
1063
|
+
job_id: string;
|
|
1064
|
+
status: "queued" | "processing" | "completed" | "error";
|
|
1065
|
+
url?: string | null;
|
|
1066
|
+
video_url?: string | null;
|
|
1067
|
+
sprite_url?: string | null;
|
|
1068
|
+
screenshot_url?: string | null;
|
|
1069
|
+
error?: string | null;
|
|
1070
|
+
end_time?: string | null;
|
|
1071
|
+
}
|
|
928
1072
|
interface RenderSpriteResponse {
|
|
929
1073
|
/**
|
|
930
1074
|
* The rendered sprite sheet as a Blob (when format is "sprite")
|
|
@@ -957,7 +1101,7 @@ interface RenderAPIService {
|
|
|
957
1101
|
getAvailableParts(category: PartCategory, config: ApiConfig, options?: GetAvailablePartsOptions): Promise<AvailablePartsResponse>;
|
|
958
1102
|
}
|
|
959
1103
|
declare const buildApiUrl: (endpoint: string, config: ApiConfig) => string;
|
|
960
|
-
declare const buildHeaders: (config: ApiConfig) => Record<string, string>;
|
|
1104
|
+
declare const buildHeaders: (config: ApiConfig, authTokenOverride?: string) => Record<string, string>;
|
|
961
1105
|
declare const renderBuildExperimental: (request: RenderBuildRequest, config: ApiConfig) => Promise<RenderBuildResponse>;
|
|
962
1106
|
declare const renderSpriteExperimental: (request: RenderBuildRequest, config: ApiConfig) => Promise<RenderSpriteResponse>;
|
|
963
1107
|
declare const getAvailableParts: (category: PartCategory, config: ApiConfig, options?: GetAvailablePartsOptions) => Promise<AvailablePartsResponse>;
|
|
@@ -1045,4 +1189,4 @@ declare const createRenderByShareCodeJob: (shareCode: string, config: ApiConfig,
|
|
|
1045
1189
|
declare const renderByShareCode: (shareCode: string, config: ApiConfig, options?: RenderByShareCodeOptions) => Promise<RenderByShareCodeResponse>;
|
|
1046
1190
|
|
|
1047
1191
|
export { API_BASE_URL, API_ENDPOINTS, BuildRender, BuildRenderVideo, DragIcon, InstructionTooltip, LoadingErrorOverlay, PartCategory, arePartsEqual, buildApiUrl, buildHeaders, calculateCircularFrame, calculateCircularTime, createRenderByShareCodeJob, getAvailableParts, getBuildByShareCode, getPartsByIds, renderBuildExperimental, renderByShareCode, renderSpriteExperimental, useBouncePatternProgress, useBuildRender, useContinuousSpin, useSpriteRender, useSpriteScrubbing, useVideoScrubbing };
|
|
1048
|
-
export type { ApiConfig, AvailablePartsResponse, BuildRenderProps, BuildRenderVideoProps, BuildResponse, GetAvailablePartsOptions, GridSettings, PartDetails, PartDetailsWithCategory, PartsResponse, RenderAPIService, RenderBuildRequest, RenderBuildResponse, RenderByShareCodeJobResponse, RenderByShareCodeOptions, RenderByShareCodeResponse, RenderSpriteResponse, SpriteRenderInput, UseBuildRenderOptions, UseBuildRenderReturn, UseSpriteRenderOptions, UseSpriteRenderReturn };
|
|
1192
|
+
export type { ApiConfig, AvailablePartsResponse, BuildRenderProps, BuildRenderVideoProps, BuildResponse, GetAvailablePartsOptions, GridSettings, PartDetails, PartDetailsWithCategory, PartsResponse, RenderAPIService, RenderBuildRequest, RenderBuildResponse, RenderByShareCodeJobResponse, RenderByShareCodeOptions, RenderByShareCodeResponse, RenderJobCreateResponse, RenderJobStatusResponse, RenderScene, RenderSpriteResponse, SpriteRenderInput, UseBuildRenderOptions, UseBuildRenderReturn, UseSpriteRenderOptions, UseSpriteRenderReturn };
|