Skip to content

Commit

Permalink
chore: minor updates to current API (#5)
Browse files Browse the repository at this point in the history
* feat: adapt + extend current API

* doc: add docs link to readme
  • Loading branch information
thlorenz committed Aug 23, 2023
1 parent eab360b commit 6ba329b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 47 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

IronForge SDK

[Docs](https://ironforge-cloud.github.io/sdk/docs/)

## Example

```ts
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
],
"author": "Thorsten Lorenz <thlorenz@gmx.de>",
"license": "MIT",
"private": true,
"devDependencies": {
"@types/node": "^20.5.1",
"esbuild": "^0.19.2",
Expand Down
11 changes: 5 additions & 6 deletions src/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { AccountsSdk } from './accounts'
import { PLATFORM_ENV_PROD, PlatformEnv } from './types'
import { accountsHostForEnv } from './utils'
import { accountsHostWithPrefix } from './utils'

export * from './accounts'
export * from './types'
export * from './utils/cluster'
export { accountsHostForEnv } from './utils'
export { accountsHostWithPrefix, rpcHostWithPrefix } from './utils'

/**
* The Ironforge SDK which is used as an entry point to all available SDK methods.
Expand All @@ -16,13 +15,13 @@ export class IronforgeSdk {
/**
* Creates a new Ironforge SDK instance.
* @param apiKey The API key to use for all requests.
* @param env The environment to use for all requests, only provide this if you work at Ironforge :)
* @param prefix The environment to use for all requests, only provide this if you work at Ironforge :)
*/
constructor(
public apiKey: string,
env: PlatformEnv = PLATFORM_ENV_PROD
prefix?: string
) {
this._accountsHost = accountsHostForEnv(env)
this._accountsHost = accountsHostWithPrefix(prefix)
}

/**
Expand Down
34 changes: 0 additions & 34 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,37 +54,3 @@ export type AccountsRequestResultWithMetadata<T> = AccountsRequestResult<
hasMore: boolean
}
}

// -----------------
// PlatformEnv
// -----------------

/**
* Dev environment, used to develop the Ironforge platform.
*/
export const PLATFORM_ENV_DEV = 'dev'

/**
* Stage environment, used to test the Ironforge platform.
*/
export const PLATFORM_ENV_STAGE = 'stage'

/**
* Prod environment, used to run the Ironforge platform.
* This is the environment that all users of the SDK outside of Ironforge should use.
*/
export const PLATFORM_ENV_PROD = 'prod'

/**
* All possible platform environments.
*/
export const PLATFORM_ENVS = [
PLATFORM_ENV_DEV,
PLATFORM_ENV_STAGE,
PLATFORM_ENV_PROD,
] as const

/**
* PlatformEnv is a union type of all possible platform environments.
*/
export type PlatformEnv = (typeof PLATFORM_ENVS)[number]
18 changes: 12 additions & 6 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { PLATFORM_ENV_PROD, PlatformEnv } from '../types'

export * from './cluster'

export async function tryExtractResultFromResponse<T>(
Expand Down Expand Up @@ -32,10 +30,18 @@ export function requestHeaders(headers: Partial<RequestHeaders> = {}) {

/**
* Returns the accounts host for the given environment.
* @param env The environment to use for all requests, provide
* [PLATFORM_ENV_PROD] unless you work at Ironforge :)
* @param maybePrefix The prefix use for all requests, provide
*/
export function accountsHostForEnv(env: PlatformEnv) {
const prefix = env === PLATFORM_ENV_PROD ? '' : `${env}.`
export function accountsHostWithPrefix(maybePrefix?: string) {
const prefix = maybePrefix == null ? '' : `${maybePrefix}.`
return `${prefix}accounts.ironforge.network`
}

/**
* Returns the RPC host for the given environment.
* @param maybePrefix The prefix use for all requests, provide
*/
export function rpcHostWithPrefix(maybePrefix?: string) {
const prefix = maybePrefix == null ? '' : `${maybePrefix}.`
return `${prefix}rpc.ironforge.network`
}

0 comments on commit 6ba329b

Please sign in to comment.