d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
123 lines
3.6 KiB
TypeScript
123 lines
3.6 KiB
TypeScript
'use client'
|
|
|
|
export const PENDING_OAUTH_CREDENTIAL_DRAFT_KEY = 'sim.pending-oauth-credential-draft'
|
|
export const PENDING_CREDENTIAL_CREATE_REQUEST_KEY = 'sim.pending-credential-create-request'
|
|
export const PENDING_CREDENTIAL_CREATE_REQUEST_EVENT = 'sim:pending-credential-create-request'
|
|
|
|
interface PendingOAuthCredentialDraft {
|
|
workspaceId: string
|
|
providerId: string
|
|
displayName: string
|
|
existingCredentialIds: string[]
|
|
existingAccountIds: string[]
|
|
requestedAt: number
|
|
}
|
|
|
|
export interface PendingCredentialCreateRequest {
|
|
workspaceId: string
|
|
type: 'env_personal' | 'env_workspace'
|
|
envKey?: string
|
|
requestedAt: number
|
|
}
|
|
|
|
function parseJson<T>(raw: string | null): T | null {
|
|
if (!raw) return null
|
|
try {
|
|
return JSON.parse(raw) as T
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
export function readPendingOAuthCredentialDraft(): PendingOAuthCredentialDraft | null {
|
|
if (typeof window === 'undefined') return null
|
|
return parseJson<PendingOAuthCredentialDraft>(
|
|
window.sessionStorage.getItem(PENDING_OAUTH_CREDENTIAL_DRAFT_KEY)
|
|
)
|
|
}
|
|
|
|
export function writePendingOAuthCredentialDraft(payload: PendingOAuthCredentialDraft) {
|
|
if (typeof window === 'undefined') return
|
|
window.sessionStorage.setItem(PENDING_OAUTH_CREDENTIAL_DRAFT_KEY, JSON.stringify(payload))
|
|
}
|
|
|
|
export function clearPendingOAuthCredentialDraft() {
|
|
if (typeof window === 'undefined') return
|
|
window.sessionStorage.removeItem(PENDING_OAUTH_CREDENTIAL_DRAFT_KEY)
|
|
}
|
|
|
|
export function readPendingCredentialCreateRequest(): PendingCredentialCreateRequest | null {
|
|
if (typeof window === 'undefined') return null
|
|
return parseJson<PendingCredentialCreateRequest>(
|
|
window.sessionStorage.getItem(PENDING_CREDENTIAL_CREATE_REQUEST_KEY)
|
|
)
|
|
}
|
|
|
|
export function writePendingCredentialCreateRequest(payload: PendingCredentialCreateRequest) {
|
|
if (typeof window === 'undefined') return
|
|
window.sessionStorage.setItem(PENDING_CREDENTIAL_CREATE_REQUEST_KEY, JSON.stringify(payload))
|
|
window.dispatchEvent(
|
|
new CustomEvent<PendingCredentialCreateRequest>(PENDING_CREDENTIAL_CREATE_REQUEST_EVENT, {
|
|
detail: payload,
|
|
})
|
|
)
|
|
}
|
|
|
|
export function clearPendingCredentialCreateRequest() {
|
|
if (typeof window === 'undefined') return
|
|
window.sessionStorage.removeItem(PENDING_CREDENTIAL_CREATE_REQUEST_KEY)
|
|
}
|
|
|
|
export const ADD_CONNECTOR_SEARCH_PARAM = 'addConnector' as const
|
|
|
|
const OAUTH_RETURN_CONTEXT_KEY = 'sim.oauth-return-context'
|
|
|
|
export type OAuthReturnOrigin = 'workflow' | 'integrations' | 'kb-connectors'
|
|
|
|
interface OAuthReturnBase {
|
|
displayName: string
|
|
providerId: string
|
|
preCount: number
|
|
workspaceId: string
|
|
reconnect?: boolean
|
|
requestedAt: number
|
|
}
|
|
|
|
interface OAuthReturnWorkflow extends OAuthReturnBase {
|
|
origin: 'workflow'
|
|
workflowId: string
|
|
}
|
|
|
|
interface OAuthReturnIntegrations extends OAuthReturnBase {
|
|
origin: 'integrations'
|
|
}
|
|
|
|
interface OAuthReturnKBConnectors extends OAuthReturnBase {
|
|
origin: 'kb-connectors'
|
|
knowledgeBaseId: string
|
|
connectorType?: string
|
|
}
|
|
|
|
export type OAuthReturnContext =
|
|
| OAuthReturnWorkflow
|
|
| OAuthReturnIntegrations
|
|
| OAuthReturnKBConnectors
|
|
|
|
export function writeOAuthReturnContext(ctx: OAuthReturnContext) {
|
|
if (typeof window === 'undefined') return
|
|
window.sessionStorage.setItem(OAUTH_RETURN_CONTEXT_KEY, JSON.stringify(ctx))
|
|
}
|
|
|
|
export function readOAuthReturnContext(): OAuthReturnContext | null {
|
|
if (typeof window === 'undefined') return null
|
|
return parseJson<OAuthReturnContext>(window.sessionStorage.getItem(OAUTH_RETURN_CONTEXT_KEY))
|
|
}
|
|
|
|
export function consumeOAuthReturnContext(): OAuthReturnContext | null {
|
|
const ctx = readOAuthReturnContext()
|
|
if (ctx) {
|
|
window.sessionStorage.removeItem(OAUTH_RETURN_CONTEXT_KEY)
|
|
}
|
|
return ctx
|
|
}
|