Skip to content

Commit 21a67f1

Browse files
committed
Revert client
1 parent 2910d46 commit 21a67f1

File tree

8 files changed

+107
-20
lines changed

8 files changed

+107
-20
lines changed

README.md

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,33 +34,19 @@ npm i -s @icepanel/sdk
3434

3535
A full reference for this library is available [here](https://github.com/IcePanel/icepanel-js/blob/HEAD/./reference.md).
3636

37-
## Helpers
37+
## Usage
3838

3939
Use the following constant to specify the latest version.
4040
```typescript
4141
import { IcePanelClient, LandscapeVersion } from "@icepanel/sdk";
4242

43-
const landscapeId = "landscapeId";
44-
45-
const client = new IcePanelClient({ apiKey: "YOUR_API_KEY", authorization: "YOUR_AUTHORIZATION" });
46-
await client.model.objects.list({
47-
landscapeId,
48-
versionId: LandscapeVersion.Latest
43+
const client = new IcePanelClient({
44+
apiKey: "YOUR_API_KEY",
45+
apiVersion: "v1"
4946
});
50-
```
51-
52-
53-
## Usage
54-
55-
Instantiate and use the client with the following:
56-
57-
```typescript
58-
import { IcePanelClient } from "@icepanel/sdk";
59-
60-
const client = new IcePanelClient({ apiKey: "YOUR_API_KEY", authorization: "YOUR_AUTHORIZATION" });
6147
await client.model.objects.list({
62-
landscapeId: "landscapeId",
63-
versionId: "versionId"
48+
landscapeId: "YOUR_LANDSCAPE_ID",
49+
versionId: LandscapeVersion.Latest
6450
});
6551
```
6652

src/.fernignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
helpers/*
2+
index.ts
3+
IcePanelClient.ts
4+
types.ts
5+
consts.ts

src/IcePanelClient.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { IcePanelClient as Client } from "./Client"
2+
import type { BaseClientOptions } from "./BaseClient"
3+
import * as core from "./core/index"
4+
import type { IcePanelAPIVersion } from "./consts"
5+
6+
export interface IcePanelOptions extends Omit<BaseClientOptions, 'environment' | 'apiKey' | 'authorization'> {
7+
apiVersion: IcePanelAPIVersion
8+
environment?: core.Supplier<string | undefined>
9+
apiKey?: core.Supplier<string | undefined>
10+
authorization?: core.Supplier<string | undefined>
11+
}
12+
13+
export class IcePanelClient extends Client {
14+
constructor(options: IcePanelOptions) {
15+
const updatedOptions: BaseClientOptions = {
16+
...options,
17+
environment: undefined,
18+
apiKey: undefined,
19+
authorization: undefined
20+
}
21+
22+
updatedOptions.baseUrl = async () => {
23+
const baseUrl = options.baseUrl ? await core.Supplier.get(options.baseUrl) : undefined
24+
if (baseUrl) {
25+
return `https://${baseUrl}/${options.apiVersion}`
26+
}
27+
const environment = options.environment ? await core.Supplier.get(options.environment) : undefined
28+
if (environment) {
29+
return `https://api.${environment}.icepanel.cloud/${options.apiVersion}`
30+
}
31+
return `https://api.icepanel.io/${options.apiVersion}`
32+
}
33+
34+
if (options.apiKey) {
35+
updatedOptions.headers = {
36+
...updatedOptions.headers,
37+
'X-API-Key': options.apiKey
38+
}
39+
}
40+
41+
if (options.authorization) {
42+
updatedOptions.headers = {
43+
...updatedOptions.headers,
44+
Authorization: options.authorization
45+
}
46+
}
47+
48+
super(updatedOptions)
49+
}
50+
}

src/consts.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const LandscapeVersion = {
2+
Latest: 'latest'
3+
} as const;
4+
5+
export type LandscapeVersion = typeof LandscapeVersion.Latest;
6+
7+
/**
8+
* The version of the IcePanel API this client is built for
9+
* When bumping versions only specify one explicit version so clients are aware of the breaking change release.
10+
*/
11+
export type IcePanelAPIVersion = 'v1';

src/helpers/ids.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { customAlphabet } from 'nanoid'
2+
3+
const FIRESTORE_ID_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
4+
const FIRESTORE_ID_LENGTH = 20
5+
6+
export const createFirestoreId = (): string => {
7+
let autoId = ''
8+
9+
for (let i = 0; i < FIRESTORE_ID_LENGTH; i++) {
10+
autoId += FIRESTORE_ID_CHARS.charAt(
11+
Math.floor(Math.random() * FIRESTORE_ID_CHARS.length)
12+
)
13+
}
14+
return autoId
15+
}
16+
17+
const SHORT_ID_CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
18+
const SHORT_ID_LENGTH = 10
19+
20+
const nanoid = customAlphabet(SHORT_ID_CHARS)
21+
22+
export const createShortId = (size: number = SHORT_ID_LENGTH): string => nanoid(size)

src/helpers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './ids'

src/index copy.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export type { BaseClientOptions, BaseRequestOptions } from "./BaseClient.js";
2+
export { IcePanelClient } from "./IcePanelClient.js";
3+
export { IcePanelEnvironment } from "./environments.js";
4+
export { IcePanelError, IcePanelTimeoutError } from "./errors/index.js";
5+
export * from "./exports.js";
6+
export * from './types.js';
7+
export * as IcePanel from './types.js';
8+
export * from './helpers/index.js';
9+
export * from './consts.js';

src/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from "./api/requests/index.js";
2+
export * from "./api/types/index.js";
3+
export * from "./consts.js";

0 commit comments

Comments
 (0)