Skip to content

Commit

Permalink
liblab SDK update for version v0.9.0-alpha.4
Browse files Browse the repository at this point in the history
  • Loading branch information
seniorquico committed Oct 5, 2024
1 parent 17da286 commit 8a4886d
Show file tree
Hide file tree
Showing 17 changed files with 59 additions and 62 deletions.
22 changes: 12 additions & 10 deletions .manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"liblabVersion": "2.4.0",
"date": "2024-09-17T04:36:04.572Z",
"liblabVersion": "2.5.1",
"date": "2024-10-05T04:00:42.516Z",
"config": {
"apiId": 1126,
"sdkName": "salad-cloud-imds-sdk",
"sdkVersion": "0.9.0-alpha.3",
"sdkVersion": "0.9.0-alpha.4",
"liblabVersion": "2",
"deliveryMethods": ["zip"],
"languages": ["typescript"],
Expand Down Expand Up @@ -33,7 +33,7 @@
"githubRepoName": "salad-cloud-imds-sdk-go",
"ignoreFiles": [".gitignore", "./LICENSE"],
"liblabVersion": "2",
"sdkVersion": "0.9.0-alpha.3",
"sdkVersion": "0.9.0-alpha.4",
"targetBranch": "main"
},
"java": {
Expand All @@ -57,11 +57,11 @@
"homepage": "https://github.com/saladtechnologies/salad-cloud-imds-sdk-java",
"ignoreFiles": [".gitignore", "./LICENSE"],
"liblabVersion": "2",
"sdkVersion": "0.9.0-alpha.3",
"sdkVersion": "0.9.0-alpha.4",
"targetBranch": "main"
},
"python": {
"alwaysInitializeOptionals": true,
"alwaysInitializeOptionals": false,
"classifiers": [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
Expand Down Expand Up @@ -100,7 +100,7 @@
"githubRepoName": "salad-cloud-imds-sdk-python",
"ignoreFiles": [".gitignore", "./LICENSE"],
"liblabVersion": "2",
"sdkVersion": "0.9.0-alpha.3",
"sdkVersion": "0.9.0-alpha.4",
"targetBranch": "main"
},
"typescript": {
Expand All @@ -123,8 +123,9 @@
"homepage": "https://github.com/saladtechnologies/salad-cloud-imds-sdk-javascript",
"ignoreFiles": [".gitignore", "./LICENSE"],
"liblabVersion": "2",
"sdkVersion": "0.9.0-alpha.3",
"targetBranch": "main"
"sdkVersion": "0.9.0-alpha.4",
"targetBranch": "main",
"generateEnumAs": "enum"
}
},
"publishing": {
Expand Down Expand Up @@ -155,7 +156,7 @@
},
"multiTenant": true,
"hooksLocation": {
"bucketKey": "7207/hooks.zip",
"bucketKey": "7538/hooks.zip",
"bucketName": "prod-liblab-api-stack-hooks"
},
"includeWatermark": false,
Expand Down Expand Up @@ -184,6 +185,7 @@
"homepage": "https://github.com/saladtechnologies/salad-cloud-imds-sdk-javascript",
"ignoreFiles": [".gitignore", "./LICENSE"],
"targetBranch": "main",
"generateEnumAs": "enum",
"typescriptVersion": "5.3.3",
"zodVersion": "3.22.0",
"compilerOptions": {
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# SaladCloudImdsSdk TypeScript SDK 0.9.0-alpha.3
# SaladCloudImdsSdk TypeScript SDK 0.9.0-alpha.4

Welcome to the SaladCloudImdsSdk SDK documentation. This guide will help you get started with integrating and using the SaladCloudImdsSdk SDK in your project.

## Versions

- API version: `0.9.0-alpha.1`
- SDK version: `0.9.0-alpha.3`
- SDK version: `0.9.0-alpha.4`

## About the API

Expand Down
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "salad-cloud-imds-sdk",
"version": "0.9.0-alpha.3",
"version": "0.9.0-alpha.4",
"private": true,
"dependencies": {
"@saladtechnologies-oss/salad-cloud-imds-sdk": "file:../",
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@saladtechnologies-oss/salad-cloud-imds-sdk",
"version": "0.9.0-alpha.3",
"version": "0.9.0-alpha.4",
"description": "The SaladCloud Instance Metadata Service (IMDS). Please refer to the [SaladCloud API Documentation](https://docs.salad.com/api-reference) for more details.",
"source": "./src/index.ts",
"main": "./dist/index.js",
Expand Down
4 changes: 3 additions & 1 deletion src/http/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { HttpMetadata } from './types';
export class HttpError extends Error {
public readonly error: string;
public readonly metadata: HttpMetadata;
public readonly raw?: ArrayBuffer;

constructor(metadata: HttpMetadata, error?: string) {
constructor(metadata: HttpMetadata, raw?: ArrayBuffer, error?: string) {
super(error);
this.error = metadata.statusText;
this.metadata = metadata;
this.raw = raw;
}
}
4 changes: 1 addition & 3 deletions src/http/handlers/hook-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ export class HookHandler implements RequestHandler {
return await hook.afterResponse(nextRequest, response, hookParams);
}

const error = await hook.onError(nextRequest, response, hookParams);

throw new HttpError(error.metadata, error.error);
throw await hook.onError(nextRequest, response, hookParams);
}

private getHookParams<T>(_request: Request<T>): Map<string, string> {
Expand Down
8 changes: 8 additions & 0 deletions src/http/handlers/request-validation-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ export class RequestValidationHandler implements RequestHandler {
return params.toString();
}

if (typeof body === 'object' && !Array.isArray(body)) {
const params = new URLSearchParams();
for (const [key, value] of Object.entries(body)) {
params.append(key, value.toString());
}
return params.toString();
}

return '';
}

Expand Down
17 changes: 5 additions & 12 deletions src/http/hooks/custom-hook.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { HttpMetadata } from '../types';
import { Hook } from './hook';
import { HttpRequest, HttpResponse, HttpError } from './hook';
import { HttpRequest, HttpResponse } from './hook';
import { HttpError } from '../error';

export class CustomHook implements Hook {
public async beforeRequest(request: HttpRequest, params: Map<string, string>): Promise<HttpRequest> {
if (request.headers == null) {
request.headers = new Map<string, unknown>();
request.headers = {};

Check failure on line 8 in src/http/hooks/custom-hook.ts

View workflow job for this annotation

GitHub Actions / Test Package

Type '{}' is missing the following properties from type 'Map<string, unknown>': clear, delete, forEach, get, and 8 more.
}

request.headers.set('Metadata', 'true');
request.headers['Metadata'] = 'true';

Check failure on line 11 in src/http/hooks/custom-hook.ts

View workflow job for this annotation

GitHub Actions / Test Package

Element implicitly has an 'any' type because type 'Map<string, unknown>' has no index signature. Did you mean to call 'request.headers.set'?
return request;
}

Expand All @@ -25,13 +25,6 @@ export class CustomHook implements Hook {
response: HttpResponse<any>,
params: Map<string, string>,
): Promise<HttpError> {
return new CustomHttpError('a custom error message', response.metadata);
return new HttpError(response.metadata, response.raw);
}
}

class CustomHttpError implements HttpError {
constructor(
public error: string,
public metadata: HttpMetadata,
) {}
}
1 change: 1 addition & 0 deletions src/http/hooks/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface HttpRequest {
body?: BodyInit;
abortSignal?: AbortSignal;
queryParams: Map<string, unknown>;
pathParams: Map<string, unknown>;
}

interface HttpMetadata {
Expand Down
1 change: 1 addition & 0 deletions src/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export type {
HttpResponse,
} from './types.ts';
export type { HttpError } from './error.ts';
export type { Environment } from './environment.ts';
12 changes: 4 additions & 8 deletions src/http/transport/request-fetch-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class RequestFetchAdapter<T> implements HttpAdapter {
this.setMethod(request.method);
this.setHeaders(request.getHeaders());
this.setBody(request.body);
this.setTimeout(request.config.timeout);
this.setTimeout(request.config.timeoutMs);
}

public async send(): Promise<HttpResponse<T>> {
Expand All @@ -25,10 +25,6 @@ export class RequestFetchAdapter<T> implements HttpAdapter {
headers: this.getHeaders(response),
};

if (metadata.status >= 400) {
throw new HttpError(metadata);
}

return {
metadata,
raw: await response.clone().arrayBuffer(),
Expand Down Expand Up @@ -66,14 +62,14 @@ export class RequestFetchAdapter<T> implements HttpAdapter {
};
}

private setTimeout(timeout: number | undefined) {
if (!timeout) {
private setTimeout(timeoutMs: number | undefined) {
if (!timeoutMs) {
return;
}

this.requestInit = {
...this.requestInit,
signal: AbortSignal.timeout(timeout),
signal: AbortSignal.timeout(timeoutMs),
};
}

Expand Down
11 changes: 0 additions & 11 deletions src/http/transport/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,6 @@ export class Request<T = unknown, PageSchema = unknown[]> {
this.body = hookRequest.body;
}

public toHookRequest(): HttpRequest {
return {
baseUrl: this.baseUrl,
method: this.method,
path: this.path,
headers: this.headers,
body: this.body,
queryParams: this.queryParams,
};
}

public constructFullUrl(): string {
const queryString = new QuerySerializer().serialize(this.queryParams);
const path = this.constructPath();
Expand Down
7 changes: 7 additions & 0 deletions src/http/transport/transport-hook-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class TransportHookAdapter<T> {
body: newRequest.body,
queryParams: this.hookParamsToTransportParams(newRequest.queryParams, request.queryParams, true),
headers: this.hookParamsToTransportParams(newRequest.headers, request.headers, false),
pathParams: this.hookParamsToTransportParams(newRequest.pathParams, request.headers, false),
});

return newTransportRequest;
Expand Down Expand Up @@ -53,13 +54,19 @@ export class TransportHookAdapter<T> {
hookQueryParams.set(key, queryParam.value);
});

const hookPathParams: Map<string, unknown> = new Map();
request.pathParams.forEach((pathParam, key) => {
hookPathParams.set(key, pathParam.value);
});

const hookRequest: HttpRequest = {
baseUrl: request.baseUrl,
method: request.method,
path: request.path,
headers: hookHeaders,
body: request.body,
queryParams: hookQueryParams,
pathParams: hookPathParams,
};
return hookRequest;
}
Expand Down
2 changes: 1 addition & 1 deletion src/http/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD';
export interface SdkConfig {
baseUrl?: string;
environment?: Environment;
timeout?: number;
timeoutMs?: number;
retry?: RetryOptions;
validation?: ValidationOptions;
}
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export class SaladCloudImdsSdk {
this.metadata.baseUrl = environment;
}

set timeout(timeout: number) {
this.metadata.timeout = timeout;
set timeoutMs(timeoutMs: number) {
this.metadata.timeoutMs = timeoutMs;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/services/base-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class BaseService {
this.config.environment = environment;
}

set timeout(timeout: number) {
this.config.timeout = timeout;
set timeoutMs(timeoutMs: number) {
this.config.timeoutMs = timeoutMs;
}
}

0 comments on commit 8a4886d

Please sign in to comment.