Skip to main content

Environment Configuration

Learn about different environments and how to configure your integration for each one.

Available Environments

Sakneen provides multiple environments for different stages of development and deployment:

Production

  • Base URL: https://your-domain
  • Full Endpoint: https://your-domain/external/apis/v1.0/
  • Usage: Live applications and production workloads
  • Rate Limits: Standard production limits apply

Staging

  • Base URL: https://your-staging-domain
  • Full Endpoint: https://your-staging-domain/external/apis/v1.0/
  • Usage: Testing and staging environments
  • Rate Limits: Relaxed limits for testing

Development (Local)

  • Base URL: http://localhost:8080
  • Full Endpoint: http://localhost:8080/external/apis/v1.0/
  • Usage: Local development and testing
  • Note: Only available when running Sakneen locally

Important: Contact Sakneen support to get your specific domain names for production and staging environments.

Environment-Specific Configuration

Using Environment Variables

// .env file
SAKNEEN_API_KEY = your - api - key - here;
SAKNEEN_DOMAIN = your - domain;
NODE_ENV = production;

// application code
const baseDomain = process.env.SAKNEEN_DOMAIN || "your-domain";
const apiKey = process.env.SAKNEEN_API_KEY;

const saveLead = async (leadPayload) => {
const response = await fetch(
`https://${baseDomain}/external/apis/v1.0/leads`,
{
method: "POST",
headers: {
"api-key": apiKey,
"Content-Type": "application/json",
language: "en-us",
},
body: JSON.stringify(leadPayload),
},
);

return response;
};

Configuration Class

class SakneenApiConfig {
constructor(environment = "production") {
this.environment = environment;
this.config = this.getConfig(environment);
}

getConfig(environment) {
const configs = {
production: {
domain: process.env.SAKNEEN_DOMAIN || "your-domain",
timeout: 30000,
retries: 3,
},
staging: {
domain: process.env.SAKNEEN_STAGING_DOMAIN || "your-staging-domain",
timeout: 60000,
retries: 5,
},
development: {
domain: "localhost:8080",
protocol: "http",
timeout: 10000,
retries: 1,
},
};

return configs[environment] || configs.production;
}

getEndpoint(path) {
const protocol = this.config.protocol || "https";
return `${protocol}://${this.config.domain}/external/apis/v1.0${path}`;
}
}

// Usage
const config = new SakneenApiConfig(process.env.NODE_ENV);
const leadEndpoint = config.getEndpoint("/leads");

Best Practices

1. Environment Detection

Always detect the environment automatically when possible:

const getEnvironment = () => {
if (process.env.NODE_ENV === "production") return "production";
if (process.env.NODE_ENV === "staging") return "staging";
return "development";
};

2. API Key Management

  • Use different API keys for each environment
  • Store keys securely using environment variables
  • Never commit API keys to version control

3. Error Handling

Different environments may have different error handling requirements:

const handleError = (error, environment) => {
if (environment === "development") {
console.error("Detailed error:", error);
} else {
// Log to monitoring service in production
logger.error("API Error", { message: error.message });
}
};

4. Rate Limiting

Be aware of different rate limits per environment and implement appropriate retry logic.

Testing Across Environments

Environment-Specific Tests

describe("Sakneen API Integration", () => {
const environment = process.env.TEST_ENVIRONMENT || "staging";
const config = new SakneenApiConfig(environment);

test("should save lead successfully", async () => {
const leadPayload = {
recordSystemId: "env-test-lead-001",
data: {
name: "Test User",
phoneNumber: "+1234567890",
project: "Test Project",
email: "[email protected]",
leadSource: "Website",
},
additionalData: {
environment,
},
};

const response = await fetch(config.getEndpoint("/leads"), {
method: "POST",
headers: {
"api-key": process.env.SAKNEEN_API_KEY,
"Content-Type": "application/json",
language: "en-us",
},
body: JSON.stringify(leadPayload),
});

expect(response.status).toBe(201);
});
});