@sylphx/sdk 0.8.0-rc.1 → 0.8.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 +35 -27
- package/dist/health/index.mjs +0 -10
- package/dist/health/index.mjs.map +1 -1
- package/dist/index.d.ts +75 -19
- package/dist/index.mjs +39 -9
- package/dist/index.mjs.map +1 -1
- package/dist/nextjs/index.d.ts +17 -6
- package/dist/nextjs/index.mjs +181 -15
- package/dist/nextjs/index.mjs.map +1 -1
- package/dist/react/index.d.ts +125 -6
- package/dist/react/index.mjs +4920 -46407
- package/dist/react/index.mjs.map +1 -1
- package/dist/server/index.d.ts +38 -10
- package/dist/server/index.mjs +5 -5
- package/dist/server/index.mjs.map +1 -1
- package/dist/web-analytics.mjs.map +1 -1
- package/package.json +9 -16
- package/dist/health/index.js +0 -521
- package/dist/health/index.js.map +0 -1
- package/dist/index.d.cts +0 -9394
- package/dist/index.js +0 -11231
- package/dist/index.js.map +0 -1
- package/dist/nextjs/index.d.cts +0 -567
- package/dist/nextjs/index.js +0 -2081
- package/dist/nextjs/index.js.map +0 -1
- package/dist/react/index.d.cts +0 -14250
- package/dist/react/index.js +0 -81688
- package/dist/react/index.js.map +0 -1
- package/dist/server/index.d.cts +0 -1842
- package/dist/server/index.js +0 -3430
- package/dist/server/index.js.map +0 -1
- package/dist/web-analytics.js +0 -248
- package/dist/web-analytics.js.map +0 -1
package/dist/server/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { SdkBillingPlan, SdkConsentType } from '@sylphx/contract';
|
|
2
|
-
import { OAuthProvider } from '@sylphx/ui';
|
|
3
|
-
export { OAuthProvider } from '@sylphx/ui';
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* REST Client for Sylphx Platform
|
|
@@ -194,7 +192,7 @@ declare class InvalidConnectionUrlError extends Error {
|
|
|
194
192
|
* import { createClient } from '@sylphx/sdk'
|
|
195
193
|
*
|
|
196
194
|
* const sylphx = createClient(process.env.SYLPHX_URL!)
|
|
197
|
-
* // Parses: sylphx://pk_prod_{hex}@bold-river-a1b2c3.sylphx.com
|
|
195
|
+
* // Parses: sylphx://pk_prod_{hex}@bold-river-a1b2c3.api.sylphx.com
|
|
198
196
|
* ```
|
|
199
197
|
*/
|
|
200
198
|
|
|
@@ -213,7 +211,7 @@ interface SylphxConfig {
|
|
|
213
211
|
readonly env: 'dev' | 'stg' | 'prod' | 'prev';
|
|
214
212
|
/** Resource slug (first DNS label), e.g. 'bold-river-a1b2c3' */
|
|
215
213
|
readonly slug: string;
|
|
216
|
-
/** Pre-computed API base URL, e.g. 'https://bold-river-a1b2c3.sylphx.com/v1' */
|
|
214
|
+
/** Pre-computed API base URL, e.g. 'https://bold-river-a1b2c3.api.sylphx.com/v1' */
|
|
217
215
|
readonly baseUrl: string;
|
|
218
216
|
/** Optional access token for authenticated requests */
|
|
219
217
|
readonly accessToken?: string;
|
|
@@ -266,7 +264,7 @@ interface SylphxClientInput {
|
|
|
266
264
|
* @example Connection URL (recommended)
|
|
267
265
|
* ```typescript
|
|
268
266
|
* const sylphx = createClient(process.env.NEXT_PUBLIC_SYLPHX_URL!)
|
|
269
|
-
* // Parses: sylphx://pk_prod_{hex}@bold-river-a1b2c3.sylphx.com
|
|
267
|
+
* // Parses: sylphx://pk_prod_{hex}@bold-river-a1b2c3.api.sylphx.com
|
|
270
268
|
* ```
|
|
271
269
|
*
|
|
272
270
|
* @example Explicit components
|
|
@@ -287,7 +285,7 @@ declare function createClient(input: string | SylphxClientInput): SylphxConfig;
|
|
|
287
285
|
* @example Connection URL (recommended)
|
|
288
286
|
* ```typescript
|
|
289
287
|
* const sylphx = createServerClient(process.env.SYLPHX_SECRET_URL!)
|
|
290
|
-
* // Parses: sylphx://sk_prod_{hex}@bold-river-a1b2c3.sylphx.com
|
|
288
|
+
* // Parses: sylphx://sk_prod_{hex}@bold-river-a1b2c3.api.sylphx.com
|
|
291
289
|
* ```
|
|
292
290
|
*
|
|
293
291
|
* @example Explicit components
|
|
@@ -622,6 +620,32 @@ declare function validateAndSanitizeKey(key: string | undefined | null): string;
|
|
|
622
620
|
*/
|
|
623
621
|
declare function isDevelopmentRuntime(): boolean;
|
|
624
622
|
|
|
623
|
+
/**
|
|
624
|
+
* OAuth SDK — customer-app-facing social login (ADR-089 Phase 4a)
|
|
625
|
+
*
|
|
626
|
+
* Backed by `apps/runtime/src/server/runtime/routes/oauth.ts`:
|
|
627
|
+
*
|
|
628
|
+
* POST /oauth/authorize — initiate OAuth flow, returns provider URL
|
|
629
|
+
*
|
|
630
|
+
* The per-provider callback handler is a browser-side redirect endpoint
|
|
631
|
+
* on the runtime (`GET /oauth/callback/{provider}`); SDK consumers
|
|
632
|
+
* redirect the user to `authorizationUrl`, then receive a `code` on
|
|
633
|
+
* their own `redirect_uri` which they exchange via `signIn()` or
|
|
634
|
+
* `auth/login` with grant_type=authorization_code.
|
|
635
|
+
*
|
|
636
|
+
* PKCE is required per OAuth 2.1. Callers MUST generate `code_verifier`
|
|
637
|
+
* + `code_challenge` and persist the verifier in session / cookie for
|
|
638
|
+
* the subsequent token exchange — this SDK does not retain state.
|
|
639
|
+
*
|
|
640
|
+
* ## Distinction from `auth.oauth`
|
|
641
|
+
*
|
|
642
|
+
* `auth.oauth.*` (from `./auth`) targets platform-plane admin mint
|
|
643
|
+
* (`/auth/platform-jwt/mint`) used by Console / CLI. The functions
|
|
644
|
+
* here target the customer-app social-login flow.
|
|
645
|
+
*/
|
|
646
|
+
|
|
647
|
+
type OAuthProvider = OAuthProviderId | (string & {});
|
|
648
|
+
|
|
625
649
|
/**
|
|
626
650
|
* Functions Client — Serverless V8 Isolate Functions (ADR-043)
|
|
627
651
|
*
|
|
@@ -1392,7 +1416,7 @@ declare function getStreams(): StreamsClient;
|
|
|
1392
1416
|
* Sylphx Server SDK
|
|
1393
1417
|
*
|
|
1394
1418
|
* Server-side operations using REST API for type safety.
|
|
1395
|
-
* Uses connection URL (sylphx://sk_*@slug.sylphx.com) for authentication.
|
|
1419
|
+
* Uses connection URL (sylphx://sk_*@tenant-slug.api.sylphx.com) for authentication.
|
|
1396
1420
|
*
|
|
1397
1421
|
* @example
|
|
1398
1422
|
* ```typescript
|
|
@@ -1632,8 +1656,10 @@ interface FeatureFlagDefinition {
|
|
|
1632
1656
|
* import { getFeatureFlags } from '@sylphx/sdk/server'
|
|
1633
1657
|
*
|
|
1634
1658
|
* export default async function RootLayout({ children }) {
|
|
1659
|
+
* const sylphx = createServerClient(process.env.SYLPHX_URL!)
|
|
1635
1660
|
* const flags = await getFeatureFlags({
|
|
1636
|
-
* secretKey:
|
|
1661
|
+
* secretKey: sylphx.secretKey!,
|
|
1662
|
+
* platformUrl: sylphx.baseUrl.replace(/\/v[0-9]+$/, ''),
|
|
1637
1663
|
* })
|
|
1638
1664
|
* return <FeatureFlagsProvider initialFlags={flags}>{children}</FeatureFlagsProvider>
|
|
1639
1665
|
* }
|
|
@@ -1687,9 +1713,11 @@ interface GetAppConfigOptions {
|
|
|
1687
1713
|
* import { getAppConfig } from '@sylphx/sdk/server'
|
|
1688
1714
|
*
|
|
1689
1715
|
* export default async function RootLayout({ children }) {
|
|
1716
|
+
* const sylphx = createServerClient(process.env.SYLPHX_URL!)
|
|
1690
1717
|
* const config = await getAppConfig({
|
|
1691
|
-
* secretKey:
|
|
1718
|
+
* secretKey: sylphx.secretKey!,
|
|
1692
1719
|
* appId: process.env.NEXT_PUBLIC_SYLPHX_APP_ID!,
|
|
1720
|
+
* platformUrl: sylphx.baseUrl.replace(/\/v[0-9]+$/, ''),
|
|
1693
1721
|
* })
|
|
1694
1722
|
*
|
|
1695
1723
|
* return (
|
|
@@ -1839,4 +1867,4 @@ declare function getDatabaseConnection(options: AuthenticatedFetchOptions): Prom
|
|
|
1839
1867
|
*/
|
|
1840
1868
|
declare function getDatabaseStatus(options: AuthenticatedFetchOptions): Promise<DatabaseStatusInfo>;
|
|
1841
1869
|
|
|
1842
|
-
export { type AIClient, type AIClientOptions, type AppConfig, type AppMetadata, type ChannelHelper, type ChatCompletionChunk, type ChatCompletionOptions, type ChatCompletionResponse, type ChatCompletionStreamOptions, type ChatMessage, type ConsentType, type DatabaseConnectionInfo, type DatabaseStatusInfo, type EmbeddingOptions, type EmbeddingResponse, type EngagementLeaderboardEntry, type EngagementLeaderboardResult, type EnvironmentType, type FeatureFlagDefinition, type FunctionDeployOptions, type FunctionDeployResult, type FunctionInvokeOptions, type FunctionListOptions, type FunctionLogEntry, type FunctionLogsOptions, type FunctionRecord, type FunctionRuntime, type FunctionStatus, FunctionsClient, type GetAppConfigOptions, InvalidConnectionUrlError, type KeyType, type KeyValidationResult, type KvClient, type KvClientOptions, type KvRateLimitResult, type KvSetOptions, type KvZMember, type ModelInfo, type ModelsResponse, type OAuthProviderInfo, type Plan, type ReferralLeaderboardEntry, type ReferralLeaderboardResult, type RestClient, type RestClientConfig as ServerClientConfig, type ServerConfig, type StreamHistoryOptions, type StreamMessage, type StreamsClient, type StreamsClientOptions, type SylphxClientInput, type SylphxConfig, type WebhookPayload, type WebhookVerifyOptions, type WebhookVerifyResult, createAI, createAuthenticatedServerClient, createClient, createKv, createServerClient, createServerRestClient, createStreams, createWebhookHandler, decodeUserId, detectEnvironment, detectKeyType, encodeUserId, getAI, getAppConfig, getAppMetadata, getConsentTypes, getCookieNamespace, getDatabaseConnection, getDatabaseStatus, getEngagementLeaderboard, getFeatureFlags, getJwks, getKv, getOAuthProviders, getOAuthProvidersWithInfo, getPlans, getReferralLeaderboard, getStreams, isAppId, isDevelopmentKey, isDevelopmentRuntime, isProductionKey, isSecretKey, resetJwksCache, validateAndSanitizeAppId, validateAndSanitizeKey, validateAndSanitizeSecretKey, validateAppId, validateKey, validateSecretKey, verifyAccessToken, verifyWebhook };
|
|
1870
|
+
export { type AIClient, type AIClientOptions, type AppConfig, type AppMetadata, type ChannelHelper, type ChatCompletionChunk, type ChatCompletionOptions, type ChatCompletionResponse, type ChatCompletionStreamOptions, type ChatMessage, type ConsentType, type DatabaseConnectionInfo, type DatabaseStatusInfo, type EmbeddingOptions, type EmbeddingResponse, type EngagementLeaderboardEntry, type EngagementLeaderboardResult, type EnvironmentType, type FeatureFlagDefinition, type FunctionDeployOptions, type FunctionDeployResult, type FunctionInvokeOptions, type FunctionListOptions, type FunctionLogEntry, type FunctionLogsOptions, type FunctionRecord, type FunctionRuntime, type FunctionStatus, FunctionsClient, type GetAppConfigOptions, InvalidConnectionUrlError, type KeyType, type KeyValidationResult, type KvClient, type KvClientOptions, type KvRateLimitResult, type KvSetOptions, type KvZMember, type ModelInfo, type ModelsResponse, type OAuthProvider, type OAuthProviderInfo, type Plan, type ReferralLeaderboardEntry, type ReferralLeaderboardResult, type RestClient, type RestClientConfig as ServerClientConfig, type ServerConfig, type StreamHistoryOptions, type StreamMessage, type StreamsClient, type StreamsClientOptions, type SylphxClientInput, type SylphxConfig, type WebhookPayload, type WebhookVerifyOptions, type WebhookVerifyResult, createAI, createAuthenticatedServerClient, createClient, createKv, createServerClient, createServerRestClient, createStreams, createWebhookHandler, decodeUserId, detectEnvironment, detectKeyType, encodeUserId, getAI, getAppConfig, getAppMetadata, getConsentTypes, getCookieNamespace, getDatabaseConnection, getDatabaseStatus, getEngagementLeaderboard, getFeatureFlags, getJwks, getKv, getOAuthProviders, getOAuthProvidersWithInfo, getPlans, getReferralLeaderboard, getStreams, isAppId, isDevelopmentKey, isDevelopmentRuntime, isProductionKey, isSecretKey, resetJwksCache, validateAndSanitizeAppId, validateAndSanitizeKey, validateAndSanitizeSecretKey, validateAppId, validateKey, validateSecretKey, verifyAccessToken, verifyWebhook };
|
package/dist/server/index.mjs
CHANGED
|
@@ -2112,7 +2112,7 @@ function parseConnectionUrl(url) {
|
|
|
2112
2112
|
// src/config.ts
|
|
2113
2113
|
var LEGACY_EMBEDDED_REF_PATTERN = /^(pk|sk)_(dev|stg|prod|prev)_[a-z0-9]{12}_[a-f0-9]+$/;
|
|
2114
2114
|
var LEGACY_APP_KEY_PATTERN = /^app_(dev|stg|prod|prev)_/;
|
|
2115
|
-
var MIGRATION_MESSAGE = "API key format has changed. Use a sylphx:// connection URL instead.\n\nNew format: sylphx://pk_prod_{hex}@your-slug.sylphx.com\n\nGenerate new credentials from the Sylphx Console \u2192 Your App \u2192 Environments.\nSee https://docs.sylphx.com/migration for details.";
|
|
2115
|
+
var MIGRATION_MESSAGE = "API key format has changed. Use a sylphx:// connection URL instead.\n\nNew format: sylphx://pk_prod_{hex}@your-slug.api.sylphx.com\n\nGenerate new credentials from the Sylphx Console \u2192 Your App \u2192 Environments.\nSee https://docs.sylphx.com/migration for details.";
|
|
2116
2116
|
function rejectLegacyKeyFormat(input) {
|
|
2117
2117
|
const trimmed = input.trim().toLowerCase();
|
|
2118
2118
|
if (LEGACY_APP_KEY_PATTERN.test(trimmed)) {
|
|
@@ -2155,7 +2155,7 @@ function createServerClient(input) {
|
|
|
2155
2155
|
function createConfigFromUrl(url) {
|
|
2156
2156
|
if (!url || typeof url !== "string") {
|
|
2157
2157
|
throw new SylphxError(
|
|
2158
|
-
"[Sylphx] Connection URL is required. Set SYLPHX_URL or NEXT_PUBLIC_SYLPHX_URL environment variable.\n\nFormat: sylphx://pk_prod_{hex}@your-slug.sylphx.com",
|
|
2158
|
+
"[Sylphx] Connection URL is required. Set SYLPHX_URL or NEXT_PUBLIC_SYLPHX_URL environment variable.\n\nFormat: sylphx://pk_prod_{hex}@your-slug.api.sylphx.com",
|
|
2159
2159
|
{ code: "BAD_REQUEST" }
|
|
2160
2160
|
);
|
|
2161
2161
|
}
|
|
@@ -2164,7 +2164,7 @@ function createConfigFromUrl(url) {
|
|
|
2164
2164
|
if (!trimmed.startsWith("sylphx://")) {
|
|
2165
2165
|
if (CREDENTIAL_REGEX.test(trimmed)) {
|
|
2166
2166
|
throw new SylphxError(
|
|
2167
|
-
"[Sylphx] Received a bare credential instead of a connection URL.\n\nWrap it in a connection URL: sylphx://<credential>@<slug>.sylphx.com\nOr use createClient({ slug, publicKey }) for explicit components.",
|
|
2167
|
+
"[Sylphx] Received a bare credential instead of a connection URL.\n\nWrap it in a connection URL: sylphx://<credential>@<slug>.api.sylphx.com\nOr use createClient({ slug, publicKey }) for explicit components.",
|
|
2168
2168
|
{ code: "BAD_REQUEST" }
|
|
2169
2169
|
);
|
|
2170
2170
|
}
|
|
@@ -2209,7 +2209,7 @@ function createConfigFromComponents(input) {
|
|
|
2209
2209
|
const credentialType = match[1];
|
|
2210
2210
|
const env = match[2];
|
|
2211
2211
|
const slug = resolvedSlug.trim().toLowerCase();
|
|
2212
|
-
const domain = input.domain?.trim() ||
|
|
2212
|
+
const domain = input.domain?.trim() || DEFAULT_SDK_API_HOST;
|
|
2213
2213
|
const baseUrl = `https://${slug}.${domain}/v1`;
|
|
2214
2214
|
return freezeConfig({
|
|
2215
2215
|
credential: trimmedCred,
|
|
@@ -2232,7 +2232,7 @@ function createConfigFromComponents(input) {
|
|
|
2232
2232
|
const platform = input.platformUrl.trim().replace(/\/$/, "");
|
|
2233
2233
|
baseUrl = platform.includes("/v1") ? platform : `${platform}/v1`;
|
|
2234
2234
|
} else {
|
|
2235
|
-
const domain = input.domain?.trim() ||
|
|
2235
|
+
const domain = input.domain?.trim() || DEFAULT_SDK_API_HOST;
|
|
2236
2236
|
baseUrl = `https://${slug}.${domain}/v1`;
|
|
2237
2237
|
}
|
|
2238
2238
|
return freezeConfig({
|