Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: Fix types and titles in interfaces #139

Merged
merged 3 commits into from
Jul 17, 2023
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 engine-idk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poozle/engine-idk",
"version": "0.1.18",
"version": "0.1.21",
"description": "Used to develop integrations for Poozle",
"license": "MIT",
"author": "Poozle <support@poozle.in>",
Expand Down
14 changes: 9 additions & 5 deletions engine-idk/src/bases/base_integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unused-vars */

import { AxiosHeaders } from 'axios';
import { getAccessToken, interpolateHeaders, interpolateString } from 'utils/oAuthUtils';

import {
Expand All @@ -14,6 +15,8 @@ import {
Params,
} from 'types/integration';

import { BasePath } from './base_path';

export class BaseIntegration implements BaseIntegrationInterface {
/*
This will return the spec for the integration
Expand Down Expand Up @@ -71,17 +74,18 @@ export class BaseIntegration implements BaseIntegrationInterface {
}
}

models(): any[] {
paths(): any[] {
return [];
}

async run(path: string, method: string, config: Config, params: Params): RunResponse {
const models = this.models();
const paths = this.paths();

const modelToRun = models.find((model) => model.hasPath(path, method));
const pathToRun: BasePath | undefined = paths.find((p) => p.isPath(path, method));

if (modelToRun) {
return await modelToRun.run(path, method, await this.authHeaders(config), params, config);
if (pathToRun) {
const headers = await this.authHeaders(config);
return await pathToRun.baseRun(method, headers as AxiosHeaders, params, config);
}

return {
Expand Down
51 changes: 0 additions & 51 deletions engine-idk/src/bases/base_model.ts

This file was deleted.

46 changes: 16 additions & 30 deletions engine-idk/src/bases/base_path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@
/* eslint-disable @typescript-eslint/no-unused-vars */

import { AxiosHeaders } from 'axios';
import { convertToModelKeys } from 'utils';

import { Config, Params } from 'types/integration';
import { Meta } from 'types/path';

export class BasePath {
pathRegex: RegExp;
method: string | string[];
schema: Record<string, any>;

constructor(pathRegex: RegExp, method: string | string[], schema: Record<string, any>) {
constructor(pathRegex: RegExp, method: string | string[]) {
this.pathRegex = pathRegex;
this.method =
typeof method === 'string' ? method.toLowerCase() : method.map((m) => m.toLowerCase());
this.schema = schema;
}

isMatchingMethod(method: string): boolean {
Expand All @@ -32,13 +29,6 @@ export class BasePath {
return this.pathRegex.test(path) && this.isMatchingMethod(method);
}

convertToModel(data: any, raw: boolean) {
const raw_data = data['raw_data'];
delete data['raw_data'];

return convertToModelKeys(data, this.schema, raw_data, raw);
}

async baseRun(method: string, headers: AxiosHeaders, params: Params, config: Config) {
const responseFromRun: any = await this.run(method, headers, params, config);

Expand All @@ -47,28 +37,24 @@ export class BasePath {
return responseFromRun;
}

if (responseFromRun.meta && Array.isArray(responseFromRun.data)) {
const data = responseFromRun.data.map((responseItem: any) =>
this.convertToModel(
responseItem,
params.queryParams?.raw === true || params.queryParams?.raw === 'true' ? true : false,
),
);
const response: any = {
data: responseFromRun.data,
};

if (responseFromRun.meta && Array.isArray(responseFromRun.data)) {
const meta = await this.getMetaParams(responseFromRun, params);

return {
data,
meta,
};
response['meta'] = meta;
}

return {
data: this.convertToModel(
responseFromRun,
params.queryParams?.raw === true || params.queryParams?.raw === 'true' ? true : false,
),
};
if (
(params.queryParams?.raw === true || params.queryParams?.raw === 'true' ? true : false) &&
responseFromRun.raw
) {
response['raw'] = responseFromRun.raw;
}

return response;
}

// Written by the integration
Expand All @@ -77,12 +63,12 @@ export class BasePath {
typeof params.queryParams?.cursor === 'string' ? params.queryParams?.cursor : '';

const next_cursor = response.meta ? response.meta.next_cursor : '';
const before_cursor = response.meta ? response.meta.previous_cursor ?? '' : '';
const previous_cursor = response.meta ? response.meta.previous_cursor ?? '' : '';

return {
limit: 0,
cursors: {
before: before_cursor,
previous: previous_cursor,
current: current_cursor,
next: next_cursor,
},
Expand Down
1 change: 0 additions & 1 deletion engine-idk/src/bases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@

export * from './base_integration';
export * from './base_path';
export * from './base_model';
57 changes: 57 additions & 0 deletions engine-idk/src/common_models/documentation/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"type": "object",
"properties": {
"id": {
"type": "string"
},
"parent_id": {
"type": "string"
},
"block_type": {
"type": "string"
},
"content": {
"type": "array",
"items": [
{
"annotations": {
"type": "array",
"items": [
{
"properties": {
"bold": {
"type": "string"
},
"italic": {
"type": "string"
},
"strikethrough": {
"type": "string"
},
"underline": {
"type": "string"
},
"code": {
"type": "string"
},
"type": {
"type": "string"
}
}
}
]
},
"plain_text": {
"type": "string"
},
"href": {
"type": "string"
}
}
]
},
"children": {
"type": "array"
}
}
}
Loading