@comergehq/studio 0.1.3 → 0.1.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comergehq/studio",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Comerge studio",
5
5
  "main": "src/index.ts",
6
6
  "module": "dist/index.mjs",
@@ -2,6 +2,9 @@ import axios from "axios";
2
2
 
3
3
  import { BASE_URL } from "./baseUrl";
4
4
 
5
+ const CLIENT_KEY_HEADER = "x-comerge-api-key";
6
+ let clientApiKey: string | null = null;
7
+
5
8
  export const publicApi = axios.create({
6
9
  baseURL: BASE_URL,
7
10
  timeout: 30_000,
@@ -11,4 +14,20 @@ export const publicApi = axios.create({
11
14
  },
12
15
  });
13
16
 
17
+ export function setClientApiKey(apiKey: string) {
18
+ const trimmed = apiKey?.trim?.() ?? "";
19
+ if (!trimmed) {
20
+ throw new Error("comerge-studio: apiKey is required");
21
+ }
22
+ clientApiKey = trimmed;
23
+ publicApi.defaults.headers.common[CLIENT_KEY_HEADER] = trimmed;
24
+ }
25
+
26
+ publicApi.interceptors.request.use((config) => {
27
+ if (!clientApiKey) return config;
28
+ config.headers = config.headers ?? {};
29
+ (config.headers as any)[CLIENT_KEY_HEADER] = clientApiKey;
30
+ return config;
31
+ });
32
+
14
33
 
@@ -15,23 +15,16 @@ import { RuntimeRenderer } from './ui/RuntimeRenderer';
15
15
  import { StudioOverlay } from './ui/StudioOverlay';
16
16
 
17
17
  export type ComergeStudioProps = {
18
- /**
19
- * App to open in the runtime and studio.
20
- */
21
18
  appId: string;
22
- /**
23
- * App root key exposed by the bundle (defaults to MicroMain).
24
- */
19
+ apiKey: string;
25
20
  appKey?: string;
26
- /**
27
- * Optional callback for a “home” button.
28
- */
29
21
  onNavigateHome?: () => void;
30
22
  style?: ViewStyle;
31
23
  };
32
24
 
33
25
  export function ComergeStudio({
34
26
  appId,
27
+ apiKey,
35
28
  appKey = 'MicroMain',
36
29
  onNavigateHome,
37
30
  style,
@@ -50,7 +43,7 @@ export function ComergeStudio({
50
43
  const captureTargetRef = React.useRef<View | null>(null);
51
44
 
52
45
  return (
53
- <StudioBootstrap>
46
+ <StudioBootstrap apiKey={apiKey}>
54
47
  {({ userId }) => (
55
48
  <BottomSheetModalProvider>
56
49
  <ComergeStudioInner
@@ -16,8 +16,8 @@ export type StudioBootstrapProps = UseStudioBootstrapOptions & {
16
16
  renderError?: (error: Error) => React.ReactNode;
17
17
  };
18
18
 
19
- export function StudioBootstrap({ children, fallback, renderError }: StudioBootstrapProps) {
20
- const { ready, error, userId } = useStudioBootstrap({});
19
+ export function StudioBootstrap({ children, fallback, renderError, apiKey }: StudioBootstrapProps) {
20
+ const { ready, error, userId } = useStudioBootstrap({ apiKey });
21
21
 
22
22
  if (error) {
23
23
  return (
@@ -1,10 +1,13 @@
1
1
  import * as React from 'react';
2
2
 
3
+ import { setClientApiKey } from '../../core/services/http/public';
3
4
  import { ensureAuthenticatedSession, ensureAnonymousSession } from '../../core/services/supabase/auth';
4
5
  import { isSupabaseClientInjected, setSupabaseConfig } from '../../core/services/supabase/client';
5
6
  import { studioConfigRepository } from '../../data/public/studio-config/repository';
6
7
 
7
- export type UseStudioBootstrapOptions = {};
8
+ export type UseStudioBootstrapOptions = {
9
+ apiKey: string;
10
+ };
8
11
 
9
12
  export type StudioBootstrapState = {
10
13
  ready: boolean;
@@ -12,7 +15,7 @@ export type StudioBootstrapState = {
12
15
  error: Error | null;
13
16
  };
14
17
 
15
- export function useStudioBootstrap(options?: UseStudioBootstrapOptions): StudioBootstrapState {
18
+ export function useStudioBootstrap(options: UseStudioBootstrapOptions): StudioBootstrapState {
16
19
  const [state, setState] = React.useState<StudioBootstrapState>({
17
20
  ready: false,
18
21
  userId: null,
@@ -24,6 +27,7 @@ export function useStudioBootstrap(options?: UseStudioBootstrapOptions): StudioB
24
27
 
25
28
  (async () => {
26
29
  try {
30
+ setClientApiKey(options.apiKey);
27
31
  const requireAuth = isSupabaseClientInjected();
28
32
  if (!requireAuth) {
29
33
  const cfg = await studioConfigRepository.get();
@@ -43,7 +47,7 @@ export function useStudioBootstrap(options?: UseStudioBootstrapOptions): StudioB
43
47
  return () => {
44
48
  cancelled = true;
45
49
  };
46
- }, []);
50
+ }, [options.apiKey]);
47
51
 
48
52
  return state;
49
53
  }