Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ More packages will be added in the future to support additional platforms and fr
import { SupaClient } from '@supashiphq/javascript-sdk'

const client = new SupaClient({
apiKey: 'api-key',
sdkKey: 'sdk-key',
environment: 'production',
context: {
userId: '123',
Expand Down
30 changes: 15 additions & 15 deletions packages/javascript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const features = {

// Create client with features
const client = new SupaClient({
apiKey: 'your-api-key',
sdkKey: 'your-sdk-key',
environment: 'production',
features,
context: {
Expand Down Expand Up @@ -96,7 +96,7 @@ const features: FeaturesWithFallbacks = {
}

const client = new SupaClient({
apiKey: 'your-api-key',
sdkKey: 'your-sdk-key',
environment: 'production',
features,
context: {},
Expand All @@ -123,7 +123,7 @@ new SupaClient(config: SupaClientConfig)

| Option | Type | Required | Description |
| ---------------------------- | ----------------------- | -------- | ---------------------------------------------------------------------------------- |
| `apiKey` | `string` | Yes | Your Supaship API key (Project Settings -> API Keys) |
| `sdkKey` | `string` | Yes | Your Supaship SDK key (Project Settings -> SDK Keys) |
| `environment` | `string` | Yes | Environment slug (e.g., `production`, `staging`, `development`) |
| `features` | `FeaturesWithFallbacks` | Yes | Feature definitions with fallback values |
| `context` | `FeatureContext` | Yes | Default context for feature evaluation |
Expand All @@ -143,7 +143,7 @@ Use `sensitiveContextProperties` to hash selected context property values on the

```typescript
const client = new SupaClient({
apiKey: 'your-api-key',
sdkKey: 'your-sdk-key',
environment: 'production',
features,
context: {
Expand Down Expand Up @@ -200,7 +200,7 @@ const features = {
} satisfies FeaturesWithFallbacks

const client = new SupaClient({
apiKey: 'key',
sdkKey: 'key',
environment: 'production',
features,
context: {},
Expand Down Expand Up @@ -246,7 +246,7 @@ const features = {
} satisfies FeaturesWithFallbacks

const client = new SupaClient({
apiKey: 'key',
sdkKey: 'key',
environment: 'prod',
features,
context: {},
Expand Down Expand Up @@ -352,7 +352,7 @@ import { SupaClient } from '@supashiphq/javascript-sdk'
import { features } from './features'

export const client = new SupaClient({
apiKey: process.env.SUPASHIP_API_KEY!,
sdkKey: process.env.SUPASHIP_SDK_KEY!,
environment: process.env.ENVIRONMENT!,
features,
context: {},
Expand Down Expand Up @@ -383,7 +383,7 @@ const features: FeaturesWithFallbacks = {
}

const client = new SupaClient({
apiKey: 'key',
sdkKey: 'key',
environment: 'prod',
features,
context: {},
Expand All @@ -401,7 +401,7 @@ const theme = config.theme // ✅ Type-safe, inferred as 'light' literal

```typescript
const client = new SupaClient({
apiKey: 'your-api-key',
sdkKey: 'your-sdk-key',
environment: 'production',
features,
context: {
Expand Down Expand Up @@ -456,15 +456,15 @@ const features = {

// ✅ Automatic (recommended) - Toolbar auto-enabled in browser with 'auto' mode
const client = new SupaClient({
apiKey: 'your-api-key',
sdkKey: 'your-sdk-key',
environment: 'development',
features,
context: {},
})

// 🎨 Custom configuration
const client = new SupaClient({
apiKey: 'your-api-key',
sdkKey: 'your-sdk-key',
environment: 'development',
features,
context: {},
Expand All @@ -479,7 +479,7 @@ const client = new SupaClient({

// ❌ Opt-out (disable toolbar)
const client = new SupaClient({
apiKey: 'your-api-key',
sdkKey: 'your-sdk-key',
environment: 'production',
features,
context: {},
Expand Down Expand Up @@ -518,7 +518,7 @@ const features = {
} satisfies FeaturesWithFallbacks

const featureClient = new SupaClient({
apiKey: process.env.SUPASHIP_API_KEY!,
sdkKey: process.env.SUPASHIP_SDK_KEY!,
environment: 'production',
features,
context: {},
Expand Down Expand Up @@ -561,7 +561,7 @@ const features = {
} satisfies FeaturesWithFallbacks

const client = new SupaClient({
apiKey: import.meta.env.VITE_SUPASHIP_API_KEY,
sdkKey: import.meta.env.VITE_SUPASHIP_SDK_KEY,
environment: 'production',
features,
context: {},
Expand Down Expand Up @@ -619,7 +619,7 @@ export class FeatureFlagService {

constructor() {
this.client = new SupaClient({
apiKey: environment.SUPASHIP_API_KEY,
sdkKey: environment.SUPASHIP_SDK_KEY,
environment: 'production',
features,
context: {
Expand Down
36 changes: 18 additions & 18 deletions packages/javascript/src/__tests__/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jest.mock('../utils', () => ({
}))

describe('SupaClient', () => {
const mockApiKey = 'test-api-key'
const mockSdkKey = 'test-sdk-key'
const mockBaseUrl = 'https://test-api.com'
const testFeatures = {
testFeature: null,
Expand All @@ -29,7 +29,7 @@ describe('SupaClient', () => {

beforeEach((): void => {
client = new SupaClient({
apiKey: mockApiKey,
sdkKey: mockSdkKey,
environment: 'test-environment',
networkConfig: {
featuresAPIUrl: `${mockBaseUrl}/features`,
Expand All @@ -43,7 +43,7 @@ describe('SupaClient', () => {
describe('constructor and configuration', () => {
it('should use default featuresAPIUrl when not provided', (): void => {
const client = new SupaClient({
apiKey: 'test',
sdkKey: 'test',
environment: 'test-environment',
context: {},
features: {} satisfies FeaturesWithFallbacks,
Expand All @@ -53,7 +53,7 @@ describe('SupaClient', () => {

it('should use default retry configuration', (): void => {
const client = new SupaClient({
apiKey: 'test',
sdkKey: 'test',
environment: 'test-environment',
features: {} satisfies FeaturesWithFallbacks,
context: {},
Expand All @@ -65,7 +65,7 @@ describe('SupaClient', () => {

it('should use custom retry configuration', (): void => {
const client = new SupaClient({
apiKey: 'test',
sdkKey: 'test',
environment: 'test-environment',
features: {} satisfies FeaturesWithFallbacks,
context: {},
Expand All @@ -80,7 +80,7 @@ describe('SupaClient', () => {

it('should handle empty plugins array', (): void => {
const client = new SupaClient({
apiKey: 'test',
sdkKey: 'test',
environment: 'test-environment',
features: {} satisfies FeaturesWithFallbacks,
context: {},
Expand All @@ -91,7 +91,7 @@ describe('SupaClient', () => {

it('should handle undefined plugins', (): void => {
const client = new SupaClient({
apiKey: 'test',
sdkKey: 'test',
environment: 'test-environment',
features: {} satisfies FeaturesWithFallbacks,
context: {},
Expand All @@ -103,7 +103,7 @@ describe('SupaClient', () => {
describe('updateContext', () => {
it('should merge context by default', (): void => {
const testClient = new SupaClient({
apiKey: mockApiKey,
sdkKey: mockSdkKey,
environment: 'test-environment',
features: testFeatures,
context: { existing: 'value', toUpdate: 'old' },
Expand All @@ -121,7 +121,7 @@ describe('SupaClient', () => {

it('should replace context when mergeWithExisting is false', (): void => {
const testClient = new SupaClient({
apiKey: mockApiKey,
sdkKey: mockSdkKey,
environment: 'test-environment',
features: testFeatures,
context: { existing: 'value', toUpdate: 'old' },
Expand Down Expand Up @@ -150,7 +150,7 @@ describe('SupaClient', () => {
}

const testClient = new SupaClient({
apiKey: mockApiKey,
sdkKey: mockSdkKey,
environment: 'test-environment',
features: testFeatures,
context: { old: 'value' },
Expand Down Expand Up @@ -252,7 +252,7 @@ describe('SupaClient', () => {
}

const testClient = new SupaClient({
apiKey: mockApiKey,
sdkKey: mockSdkKey,
environment: 'test-environment',
features: testFeatures,
context: {},
Expand Down Expand Up @@ -290,7 +290,7 @@ describe('SupaClient', () => {
}

const testClient = new SupaClient({
apiKey: mockApiKey,
sdkKey: mockSdkKey,
environment: 'test-environment',
features: { feature1: null } satisfies FeaturesWithFallbacks,
context: { default: 'value' },
Expand Down Expand Up @@ -329,7 +329,7 @@ describe('SupaClient', () => {
}

const testClient = new SupaClient({
apiKey: mockApiKey,
sdkKey: mockSdkKey,
environment: 'test-environment',
features: {
feature1: false as boolean,
Expand Down Expand Up @@ -359,7 +359,7 @@ describe('SupaClient', () => {
}

const testClient = new SupaClient({
apiKey: mockApiKey,
sdkKey: mockSdkKey,
environment: 'test-environment',
features: { feature1: null } satisfies FeaturesWithFallbacks,
context: {},
Expand All @@ -386,7 +386,7 @@ describe('SupaClient', () => {
json: () => Promise.resolve({ features: { feature1: { variation: 'true' } } }),
} as MockResponse)
const testClient = new SupaClient({
apiKey: mockApiKey,
sdkKey: mockSdkKey,
environment: 'test-environment',
features: { feature1: null } satisfies FeaturesWithFallbacks,
context: {
Expand Down Expand Up @@ -418,7 +418,7 @@ describe('SupaClient', () => {
json: () => Promise.resolve({ features: { feature1: { variation: 'true' } } }),
} as MockResponse)
const testClient = new SupaClient({
apiKey: mockApiKey,
sdkKey: mockSdkKey,
environment: 'test-environment',
features: { feature1: null } satisfies FeaturesWithFallbacks,
context: {
Expand Down Expand Up @@ -469,7 +469,7 @@ describe('SupaClient', () => {

it('should work with retry disabled', async (): Promise<void> => {
const testClient = new SupaClient({
apiKey: mockApiKey,
sdkKey: mockSdkKey,
environment: 'test-environment',
features: { testFeature: null } satisfies FeaturesWithFallbacks,
context: {},
Expand Down Expand Up @@ -498,7 +498,7 @@ describe('SupaClient', () => {
}

const testClient = new SupaClient({
apiKey: mockApiKey,
sdkKey: mockSdkKey,
environment: 'test-environment',
features: { testFeature: null } satisfies FeaturesWithFallbacks,
context: {},
Expand Down
6 changes: 3 additions & 3 deletions packages/javascript/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type ResolvedNetworkConfig = {
}

export class SupaClient<TFeatures extends FeaturesWithFallbacks> {
private apiKey: string
private sdkKey: string
private environment: string
private defaultContext?: FeatureContext
private plugins: SupaPlugin[]
Expand All @@ -32,7 +32,7 @@ export class SupaClient<TFeatures extends FeaturesWithFallbacks> {
private networkConfig: ResolvedNetworkConfig

constructor(config: SupaClientConfig & { features: TFeatures }) {
this.apiKey = config.apiKey
this.sdkKey = config.sdkKey
this.environment = config.environment
this.defaultContext = config.context
this.featureDefinitions = config.features as Features<TFeatures>
Expand Down Expand Up @@ -285,7 +285,7 @@ export class SupaClient<TFeatures extends FeaturesWithFallbacks> {
const url = this.networkConfig.featuresAPIUrl
const headers: Record<string, string> = {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.apiKey}`,
Authorization: `Bearer ${this.sdkKey}`,
}
const requestContext = await this.hashSensitiveContext(mergedContext)
const body = JSON.stringify({
Expand Down
4 changes: 2 additions & 2 deletions packages/javascript/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ export type { SupaToolbarPluginConfig } from './plugins/toolbar-plugin'

export interface SupaClientConfig {
/**
* API key used to authenticate requests to Supaship services.
* SDK key used to authenticate requests to Supaship services.
* Typically created in your project settings.
*/
apiKey: string
sdkKey: string
/**
* Environment identifier used for feature flag evaluation (e.g. "production", "staging").
*/
Expand Down
Loading
Loading