Spectra JavaScript SDK
Spectra SDK 문서는 서버 저장소 이름보다 개발자가 하려는 일을 기준으로 읽는다.
- 로그인과 세션이 필요하면 Auth JS SDK부터 시작한다.
- 이메일 인증 코드와 push device 등록은 Notification JS SDK를 사용한다.
- 방, 메시지, typing, read, WebSocket 흐름은 Chat JS SDK를 사용한다.
- 이미지, 영상, 첨부 파일은 Storage JS SDK를 사용한다.
기본 SDK UX는 SDK UX Contract v1을 따른다. 기본 문서와 첫 예시는
key별 권한 설정, 기능별 preset, deliveryBaseURL, service token audience, templateId 같은 내부/고급 개념을 요구하지 않는다.
현재 package나 서버가 아직 이 계약과 다르면 소비 앱 workaround가 아니라 SDK/서비스 정렬 작업으로 본다.
설치
GitHub Packages를 사용한다.
npm install @spectra-platform/auth-sdk
npm install @spectra-platform/notification-sdk
npm install @spectra-platform/chat-sdk
npm install @spectra-platform/storage-sdk
소비 프로젝트의 .npmrc에는 Spectra scope registry를 추가한다.
@spectra-platform:registry=https://npm.pkg.github.com
Private package 권한이 필요한 환경에서는 GitHub Packages read token이 필요하다.
현재 문서화된 JS SDK
SDK · Package · Version · 역할
Auth JS · @spectra-platform/auth-sdk · 0.1.10 발행·설치 검증 완료 · Google/Apple 로그인, callback relay, session/token, test LAN HTTP opt-in 및 preflight, popup 보강. Backend login verification은 기존 getAccessToken()으로 사용하며 신규 SDK 버전 불필요
Notification JS · @spectra-platform/notification-sdk · 0.1.0 · 이메일 코드 요청/검증, iOS/Android push device registration
Chat JS · @spectra-platform/chat-sdk · registry 0.1.3; source 0.2.0 unpublished · room/message/realtime, 신규 self-leave는 undeployed
Storage JS · @spectra-platform/storage-sdk · 0.1.3 · user-root file upload/list/download/delete, object upload input, safe fileInfo metadata
@spectra-platform/auth-sdk@0.1.10은 2026-09-05 GitHub Packages에 수동 발행됐고 새 캐시 설치까지
검증됐다. Private package 권한이 필요한 환경에서는 GitHub Packages read 권한이 필요하다.
이번 발행은 Actions workflow 성공을 뜻하지 않으며 자동 publish 권한 문제와 구분한다.
SDK API tree
모바일 로컬 HTTP 로그인은 승인된 test 전용 개발 경로를 설명한다.
새 development.allowInsecureHttp 옵션과 preflightSignIn()은 발행·설치 검증된 0.1.10에 포함된다.
배포된 Auth/Console은 활성 Test App Client에 저장한 웹 callback origin을 Auth SDK CORS에 자동 연결한다.
JWT 및 기존 HTTPS 허용·미등록 LAN 거절은 운영 검증됐으며 LAN 저장·등록 후 검증은 가이드의 릴리즈 표를 따른다. SDK 발행만으로 LAN 로그인이
바로 가능해지는 것은 아니다. 소비 앱의 옵션·callback·실행 버전 적용과 실기기 QA도 필요하다.
이미 Auth Test면 기존 구성을 사용하며 Secret Key 환경과 혼동하지 않는다. 기존 live/localhost/HTTPS 주소는 보존한다.
Spectra JavaScript SDK
├─ Auth JS SDK
│ ├─ Client setup
│ │ ├─ new SpectraAuthClient(config)
│ │ ├─ createSpectraAuth(config)
│ │ └─ createLocalStorageSessionStore()
│ ├─ Login
│ │ ├─ signInWithGoogle(options?)
│ │ ├─ signInWithApple(options?)
│ │ └─ relaySpectraAuthCallback()
│ └─ Session and tokens
│ ├─ getSession()
│ ├─ getAccessToken(options?)
│ ├─ backend login verification token: getAccessToken() without service
│ ├─ refresh()
│ └─ logout()
├─ Notification JS SDK
│ ├─ Client setup
│ │ ├─ new SpectraNotificationClient(config)
│ │ └─ createSpectraNotificationClient(config)
│ ├─ Email verification
│ │ ├─ sendEmailCode(options)
│ │ └─ verifyEmailCode(options)
│ └─ Push registration
│ └─ registerForPush(options)
├─ Chat JS SDK
│ ├─ Client setup
│ │ ├─ new SpectraChatClient(config)
│ │ ├─ createSpectraChatClient(config)
│ │ └─ on(event, handler)
│ ├─ Rooms
│ │ ├─ listRooms(options?)
│ │ ├─ createDirectRoom({ userId })
│ │ ├─ createGroupRoom({ title?, userIds })
│ │ ├─ leaveRoom(roomId, options?) # 0.2.0 unpublished
│ │ └─ getRoomMembership(roomId, options?) # 0.2.0 unpublished
│ ├─ Messages
│ │ ├─ listMessages(roomId, options?)
│ │ ├─ sendMessage(roomId, options)
│ │ └─ markRead(roomId, { lastReadSequence })
│ └─ Realtime
│ ├─ connect(roomId)
│ ├─ setTyping(roomId, isTyping)
│ └─ disconnect()
└─ Storage JS SDK
├─ Client setup
│ ├─ new SpectraStorageClient(config)
│ └─ createSpectraStorageClient(config)
└─ Files
├─ listFiles(options?)
├─ uploadFile(input)
├─ uploadImage(input)
├─ getDownloadUrl(path)
├─ downloadBlob(path)
└─ deleteFile(path)
기본 사용 흐름
앱에는 공개 가능한 설정만 넣는다.
- Project ID
- 앱 또는 웹 callback URL
- Environment (
test또는live) - 현재 Auth SDK package가 요구하는 public/client 호환 field
제품 계약에서 사용자가 관리해야 하는 주요 값은 Project ID + Secret Key다. Secret Key는 최초 발급 또는
재발급 직후 한 번만 보여주며, Project마다 활성 key는 하나만 존재한다. 최초 발급 전과 재발급 시 새
Secret Key의 test 또는 live 환경을 선택할 수 있고, 재발급 뒤 이전 key는 더 이상 usable하지 않다.
Secret Key 자체에는 기능 권한을 담지 않고, 만료일도 두지 않는다. 사용자-facing 기본 문서는 Secret Key
만료일 입력/표시를 노출하지 않는다. Email/Push/Storage/Chat/Call 사용 가능 여부는 Project dashboard service
toggle로 결정하며, Secret Key 접근 제어는 재발급, 폐기, service 비활성화로 수행한다.
서버 발송, Storage 관리, 운영성 Push 같은 backend 작업은 앱 Backend나 secret manager에 보관한 Secret Key로
Project를 확인한 뒤 해당 service toggle이 켜져 있을 때만 수행한다. 현재 SDK/API field에 남아 있는
publicClientId는 current package compatibility로만 다루며, 서버 권한이나 사용자가 관리해야 할 주요 key로
설명하지 않는다.
기본 예시에 endpoint override를 넣지 않는다. 로컬 producer 테스트나 Platform CS 진단에서만 고급 설정으로 다룬다.
Secret과 provider credential은 다음처럼 다룬다.
- Secret Key는
test또는live환경에 묶인 만료일 없는 비밀값이며 최초 발급/재발급 직후 1회만 보여진다. 클라이언트 노출 여부는 소비 프로젝트의 앱 아키텍처 결정이다. - token expiry 설명은 app-user/session/service token 같은 별도 토큰 계약에서만 다룬다.
- Google client secret
- Apple private key
- Keycloak client secret
- SMTP, APNs, FCM credential
import {
SpectraAuthClient,
createLocalStorageSessionStore,
} from "@spectra-platform/auth-sdk";
import { SpectraStorageClient } from "@spectra-platform/storage-sdk";
const auth = new SpectraAuthClient({
projectId: "proj_...",
// Current Auth SDK compatibility field. It is not a primary product key.
publicClientId: "app_...",
environment: "test",
redirectUri: "https://myapp.example.com/auth/callback",
sessionStore: createLocalStorageSessionStore(),
});
await auth.signInWithGoogle();
const storage = new SpectraStorageClient({
projectId: "proj_...",
auth,
});
await storage.uploadFile({
file,
path: "/reviews/photo.jpg",
visibility: "private",
context: "review",
fileInfo: {
originalName: file.name,
lastModified: file.lastModified,
},
});
로컬 SDK 로그인 테스트
로컬 앱도 공개 Auth 서버를 그대로 사용할 수 있다. 이때 핵심은 앱의 redirectUri와 브라우저 origin이
Spectra Auth 서버에 허용되어 있어야 한다는 점이다.
const auth = new SpectraAuthClient({
baseUrl: "https://auth.spectra.kr",
projectId: "proj_...",
// Current Auth SDK compatibility field. It is not a primary product key.
publicClientId: "app_...",
environment: "test",
redirectUri: "http://127.0.0.1:5174/auth/callback",
});
redirectUri는 앱이 로그인 결과를 받을 URL이다. Google/Apple 개발자 콘솔에 붙여 넣는 Provider Redirect URL과 다르다.localhost와127.0.0.1은 서로 다른 origin이다. 앱을127.0.0.1로 열었다면 callback도127.0.0.1을 써야 한다.- 기존 Public test의
localhost:5173/5174,127.0.0.1:5173/5174허용 기록은 유지한다. 배포된 Test callback 등록 기반 CORS는 모바일 가이드를 따른다. - Apple credential이 아직 없는 소비 프로젝트는 Google만 먼저 검증하고 Apple은 별도 provider 준비 항목으로 둔다.
Try again later.또는RATE_LIMITED가 보이면isSpectraAuthError()로code,status,retryAfterSeconds,requestId를 확인한다.
SDK별 기능 요약
Auth JS SDK
- Google/Apple Hosted Login popup을 시작한다.
- callback page에서
relaySpectraAuthCallback()으로 로그인 결과를 원래 창에 전달한다. - app-user session을 저장하고
getSession()으로 현재 사용자 요약을 읽는다. getAccessToken()으로 Auth token 또는 service token을 가져온다.- 앱 Backend 로그인 검증에는
getAccessToken()을 옵션 없이 호출해 받은 Auth session token을 전달하고, Backend는
GET /platform/v1/auth/sessions/current 응답의 Project/client/environment/app-user를 대조한다.
getAccessToken({ service: "chat" | "storage" })로 받은 service token은 로그인 검증용이 아니며 Auth API가
AUTH_SESSION_SCOPE_FORBIDDEN으로 거절한다.
refresh()와logout()으로 session lifecycle을 관리한다.0.1.6source부터 같은 SDK 인스턴스의 동시 refresh/service-token 발급 요청은 single-flight로 합쳐지고, 429 응답은 service별 cooldown으로 보호된다.
Notification JS SDK
- Auth SDK 객체를
auth로 주입받는다. - 이메일 인증은 direct body 기반 기본 UX를 따른다. 현재
sendEmailCode()형태를 쓰더라도 첫 문서와 예시는templateId를 요구하지 않는다. verifyEmailCode()로 verification ID와 코드를 검증한다.registerForPush()로 iOS APNs 또는 Android FCM provider token을 기기 record로 등록한다.- 운영성 대량 발송은 기본 browser SDK 예시 범위가 아니다. Secret Key 사용 위치는 소비 프로젝트의 앱 아키텍처 결정이며, 문서는 Secret Key가 환경에 묶인 만료일 없는 비밀값이고 최초 발급/재발급 직후 1회만 보여진다는 사실을 전제로 한다.
Chat JS SDK
- 실제 나가기는 Chat 대화방 나가기의 본인 membership 해제다.
disconnect()와 다르며 새 기능은unpublished / undeployed다. 기존 방 1:1 재개·그룹 재초대는 미지원이다.
- Console이 아니라
chat-sdk-js/examples/webWeb example을 기준으로 Chat SDK를 테스트하고 고도화한다. - 기본 로컬 demo 주소는
http://127.0.0.1:5176이다. - demo의
VITE_SPECTRA_REDIRECT_URI=http://127.0.0.1:5176/auth/callback은 Console의 App/Web Callback URL에 등록한다. Google/Apple provider redirect URL에 넣는 값이 아니다. createDirectRoom()과createGroupRoom()으로 1:1/그룹방을 만든다.listRooms()와listMessages()로 방과 메시지를 조회한다.sendMessage()로 text 메시지를 보낸다.- 파일 전송은
sendMessageWithFiles()가 Storage 업로드와 message reference 생성을 감싼다. 현재 기본값public_readURL은 Chat 탈퇴로 회수되지 않는다.upload.visibility와 기록 접근 한계는 개별 가이드를 따른다. markRead()와setTyping()으로 읽음과 typing 상태를 전달한다.connect()로 room WebSocket channel에 연결하고 SDK가 재연결을 처리한다.
Storage JS SDK
uploadFile({ file, path, visibility, context, fileInfo })로 일반 파일이나 영상을 user-root path에 올린다.uploadImage({ file, path|directory, visibility, context, fileInfo })로 이미지 Blob을 검증하고 업로드한다.visibility는 기본적으로private이며, 공개 읽기가 필요할 때만public_read를 명시한다.fileInfo.originalName에는 한글 파일명 같은 non-ASCII 값을 넣을 수 있다. Storage API가 signed PUT header-safe 인코딩을 소유하므로 소비 앱이 S3/MinIO metadata header를 직접 만들지 않는다.listFiles()로 prefix 기준 파일과 하위 폴더 prefix를 조회한다.getDownloadUrl()과downloadBlob()으로 파일을 가져온다.deleteFile()로 user-root 파일을 삭제한다.
문서 구분
- 사람용 문서: SDK별 설치, 코드 예시, 사용자 흐름을 설명한다.
- 에이전트용 문서: 패키지명, API surface, 필요한 설정, 금지 secret, 미검증 항목을 짧고 정확하게 나열한다.
에이전트가 읽을 때는 Agent-readable SDK index를 우선 사용한다.