init
This commit is contained in:
1
.eslintignore
Normal file
1
.eslintignore
Normal file
@ -0,0 +1 @@
|
||||
/**/*.js
|
22
.eslintrc.json
Normal file
22
.eslintrc.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"env": {
|
||||
"browser": false,
|
||||
"es6": true,
|
||||
"node": true
|
||||
},
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"project": "tsconfig.json",
|
||||
"sourceType": "module",
|
||||
"ecmaVersion": 2020
|
||||
},
|
||||
"plugins": ["@typescript-eslint", "jest"],
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:jest/recommended",
|
||||
"prettier"
|
||||
],
|
||||
"rules": {}
|
||||
}
|
17
.github/workflows/nodejs.yml
vendored
Normal file
17
.github/workflows/nodejs.yml
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
name: Node.js CI
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: volta-cli/action@v1
|
||||
- run: npm ci --no-audit
|
||||
- run: npm run lint --if-present
|
||||
- run: npm test
|
||||
- run: npm run build --if-present
|
||||
env:
|
||||
CI: true
|
31
.gitignore
vendored
Normal file
31
.gitignore
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
temp
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Dependencies
|
||||
node_modules/
|
||||
|
||||
# Coverage
|
||||
coverage
|
||||
|
||||
# Transpiled files
|
||||
build/
|
||||
|
||||
# VS Code
|
||||
.vscode
|
||||
!.vscode/tasks.js
|
||||
|
||||
# JetBrains IDEs
|
||||
.idea/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Misc
|
||||
.DS_Store
|
12
.prettierrc
Normal file
12
.prettierrc
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all",
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["*.ts", "*.mts"],
|
||||
"options": {
|
||||
"parser": "typescript"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 KittyCAD
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
24
__tests__/main.test.ts
Normal file
24
__tests__/main.test.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { file } from '../src/main.js';
|
||||
import fsp from 'fs/promises';
|
||||
import { CodeOutput_type } from '../src/models.js';
|
||||
|
||||
describe('Testing create_file_execution', () => {
|
||||
it("shouldn't throw", async () => {
|
||||
const { stderr, stdout, output_files } = (await file.create_file_execution({
|
||||
lang: 'go',
|
||||
output: 'output.stl',
|
||||
body: await fsp.readFile('./exampleGoScript.go', 'base64'),
|
||||
})) as CodeOutput_type;
|
||||
expect(stderr).toBe('');
|
||||
expect(stdout).toBe(
|
||||
[
|
||||
'File conversion id: bdbf2969-8015-448b-a237-841d421fd1fe',
|
||||
'File conversion status: Completed',
|
||||
'Saving output to ./output.stl\n',
|
||||
].join('\n'),
|
||||
);
|
||||
expect(output_files[0].contents).toHaveLength(191308);
|
||||
|
||||
expect(true).toBe(true);
|
||||
});
|
||||
});
|
1
babel.config.js
Normal file
1
babel.config.js
Normal file
@ -0,0 +1 @@
|
||||
module.exports = { presets: ['@babel/preset-env'] };
|
56
exampleGoScript.go
Normal file
56
exampleGoScript.go
Normal file
@ -0,0 +1,56 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"github.com/kittycad/kittycad.go"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Create a new client with your token parsed from the environment variable:
|
||||
// KITTYCAD_API_TOKEN.
|
||||
client, err := kittycad.NewClientFromEnv("your apps user agent")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
input, _ := os.Open("./ORIGINALVOXEL-3.obj")
|
||||
|
||||
content, _ := ioutil.ReadAll(bufio.NewReader(input))
|
||||
|
||||
// Encode as base64.
|
||||
myReader := strings.NewReader(base64.StdEncoding.EncodeToString(content))
|
||||
|
||||
fc, err := client.File.CreateConversion("stl", "obj", myReader)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("File conversion id: ", fc.ID)
|
||||
fmt.Println("File conversion status: ", fc.Status)
|
||||
|
||||
decoded, err := base64.StdEncoding.DecodeString(fc.Output)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
output_file_path := "./output.stl"
|
||||
fmt.Println("Saving output to ", output_file_path)
|
||||
|
||||
output, err := os.Create(output_file_path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer output.Close()
|
||||
|
||||
if _, err := output.Write(decoded); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := output.Sync(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
23
jest.config.js
Normal file
23
jest.config.js
Normal file
@ -0,0 +1,23 @@
|
||||
export default {
|
||||
testEnvironment: 'node',
|
||||
preset: 'ts-jest',
|
||||
globals: {
|
||||
'ts-jest': {
|
||||
useESM: true,
|
||||
},
|
||||
},
|
||||
moduleNameMapper: {
|
||||
'^(\\.{1,2}/.*)\\.(m)?js$': '$1',
|
||||
},
|
||||
transform: {
|
||||
'^.+\\.(ts|tsx)?$': 'ts-jest',
|
||||
},
|
||||
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(m)?ts$',
|
||||
coverageDirectory: 'coverage',
|
||||
collectCoverageFrom: [
|
||||
'src/**/*.ts',
|
||||
'src/**/*.mts',
|
||||
'!src/**/*.d.ts',
|
||||
'!src/**/*.d.mts',
|
||||
],
|
||||
};
|
51
package.json
Normal file
51
package.json
Normal file
@ -0,0 +1,51 @@
|
||||
{
|
||||
"name": "@kittycad/lib",
|
||||
"version": "0.0.4",
|
||||
"description": "ts lib",
|
||||
"main": "build/main.js",
|
||||
"module": "build/main.es.js",
|
||||
"files": [
|
||||
"build"
|
||||
],
|
||||
"types": "build/src/**/*",
|
||||
"engines": {
|
||||
"node": ">= 16.13 <17"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/preset-env": "^7.18.9",
|
||||
"@rollup/plugin-commonjs": "^22.0.1",
|
||||
"@rollup/plugin-node-resolve": "^13.3.0",
|
||||
"@types/jest": "~27.5",
|
||||
"@types/node": "~16",
|
||||
"@typescript-eslint/eslint-plugin": "~5.26",
|
||||
"@typescript-eslint/parser": "~5.26",
|
||||
"eslint": "~8.16",
|
||||
"eslint-config-prettier": "~8.5",
|
||||
"eslint-plugin-jest": "~26.2",
|
||||
"jest": "~28.1",
|
||||
"prettier": "~2.6",
|
||||
"rimraf": "~3.0",
|
||||
"rollup": "^2.77.2",
|
||||
"rollup-plugin-peer-deps-external": "^2.2.4",
|
||||
"rollup-plugin-typescript2": "^0.32.1",
|
||||
"ts-jest": "~28.0",
|
||||
"tsutils": "~3.21",
|
||||
"typescript": "~4.7"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rm -rf build",
|
||||
"build": "yarn clean && rollup -c",
|
||||
"tsc": "tsc"
|
||||
},
|
||||
"author": "Kurt Hutten <kurt@kittycad.io>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"node-fetch": "2.6.7",
|
||||
"openapi-types": "^12.0.0",
|
||||
"ts-node": "^10.9.1",
|
||||
"tslib": "~2.4"
|
||||
},
|
||||
"volta": {
|
||||
"node": "16.13.0"
|
||||
}
|
||||
}
|
49
rollup.config.js
Normal file
49
rollup.config.js
Normal file
@ -0,0 +1,49 @@
|
||||
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
|
||||
import resolve from '@rollup/plugin-node-resolve';
|
||||
import commonjs from '@rollup/plugin-commonjs';
|
||||
import typescript from 'rollup-plugin-typescript2';
|
||||
|
||||
// this override is needed because Module format cjs does not support top-level await
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const packageJson = require('./package.json');
|
||||
|
||||
const globals = {
|
||||
...packageJson.devDependencies,
|
||||
...packageJson.dependencies,
|
||||
};
|
||||
|
||||
export default {
|
||||
input: 'src/main.ts',
|
||||
output: [
|
||||
{
|
||||
file: packageJson.main,
|
||||
format: 'cjs', // commonJS
|
||||
sourcemap: true,
|
||||
},
|
||||
{
|
||||
file: packageJson.module,
|
||||
format: 'esm', // ES Modules
|
||||
sourcemap: true,
|
||||
},
|
||||
],
|
||||
plugins: [
|
||||
peerDepsExternal(),
|
||||
resolve(),
|
||||
commonjs(),
|
||||
typescript({
|
||||
tsconfigOverride: {
|
||||
exclude: ['__tests__/**/*'],
|
||||
},
|
||||
}),
|
||||
commonjs({
|
||||
exclude: 'node_modules',
|
||||
ignoreGlobal: true,
|
||||
}),
|
||||
],
|
||||
external: Object.keys(globals),
|
||||
};
|
||||
|
||||
// Other useful plugins you might want to add are:
|
||||
// @rollup/plugin-images - import image files into your components
|
||||
// @rollup/plugin-json - import JSON files into your components
|
||||
// rollup-plugin-terser - minify the Rollup bundle
|
26
src/api/api-calls/get_api_call.ts
Normal file
26
src/api/api-calls/get_api_call.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { ApiCallWithPrice_type, Error_type } from '../../models.js';
|
||||
|
||||
interface Get_api_call_params {
|
||||
id: string;
|
||||
}
|
||||
|
||||
type Get_api_call_return = ApiCallWithPrice_type | Error_type;
|
||||
|
||||
export default async function get_api_call({
|
||||
id,
|
||||
}: Get_api_call_params): Promise<Get_api_call_return> {
|
||||
const url = `/api-calls/${id}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Get_api_call_return;
|
||||
return result;
|
||||
}
|
26
src/api/api-calls/get_api_call_for_user.ts
Normal file
26
src/api/api-calls/get_api_call_for_user.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { ApiCallWithPrice_type, Error_type } from '../../models.js';
|
||||
|
||||
interface Get_api_call_for_user_params {
|
||||
id: string;
|
||||
}
|
||||
|
||||
type Get_api_call_for_user_return = ApiCallWithPrice_type | Error_type;
|
||||
|
||||
export default async function get_api_call_for_user({
|
||||
id,
|
||||
}: Get_api_call_for_user_params): Promise<Get_api_call_for_user_return> {
|
||||
const url = `/user/api-calls/${id}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Get_api_call_for_user_return;
|
||||
return result;
|
||||
}
|
26
src/api/api-calls/get_api_call_metrics.ts
Normal file
26
src/api/api-calls/get_api_call_metrics.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { ApiCallQueryGroup_type, Error_type } from '../../models.js';
|
||||
|
||||
interface Get_api_call_metrics_params {
|
||||
group_by: string;
|
||||
}
|
||||
|
||||
type Get_api_call_metrics_return = ApiCallQueryGroup_type[] | Error_type;
|
||||
|
||||
export default async function get_api_call_metrics({
|
||||
group_by,
|
||||
}: Get_api_call_metrics_params): Promise<Get_api_call_metrics_return> {
|
||||
const url = `/api-call-metrics?group_by=${group_by}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Get_api_call_metrics_return;
|
||||
return result;
|
||||
}
|
26
src/api/api-calls/get_async_operation.ts
Normal file
26
src/api/api-calls/get_async_operation.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { AsyncApiCallOutput_type, Error_type } from '../../models.js';
|
||||
|
||||
interface Get_async_operation_params {
|
||||
id: string;
|
||||
}
|
||||
|
||||
type Get_async_operation_return = AsyncApiCallOutput_type | Error_type;
|
||||
|
||||
export default async function get_async_operation({
|
||||
id,
|
||||
}: Get_async_operation_params): Promise<Get_async_operation_return> {
|
||||
const url = `/async/operations/${id}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Get_async_operation_return;
|
||||
return result;
|
||||
}
|
30
src/api/api-calls/list_api_calls.ts
Normal file
30
src/api/api-calls/list_api_calls.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { ApiCallWithPriceResultsPage_type, Error_type } from '../../models.js';
|
||||
|
||||
interface List_api_calls_params {
|
||||
limit: string;
|
||||
page_token: string;
|
||||
sort_by: string;
|
||||
}
|
||||
|
||||
type List_api_calls_return = ApiCallWithPriceResultsPage_type | Error_type;
|
||||
|
||||
export default async function list_api_calls({
|
||||
limit,
|
||||
page_token,
|
||||
sort_by,
|
||||
}: List_api_calls_params): Promise<List_api_calls_return> {
|
||||
const url = `/api-calls?limit=${limit}&page_token=${page_token}&sort_by=${sort_by}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as List_api_calls_return;
|
||||
return result;
|
||||
}
|
34
src/api/api-calls/list_api_calls_for_user.ts
Normal file
34
src/api/api-calls/list_api_calls_for_user.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { ApiCallWithPriceResultsPage_type, Error_type } from '../../models.js';
|
||||
|
||||
interface List_api_calls_for_user_params {
|
||||
id: string;
|
||||
limit: string;
|
||||
page_token: string;
|
||||
sort_by: string;
|
||||
}
|
||||
|
||||
type List_api_calls_for_user_return =
|
||||
| ApiCallWithPriceResultsPage_type
|
||||
| Error_type;
|
||||
|
||||
export default async function list_api_calls_for_user({
|
||||
id,
|
||||
limit,
|
||||
page_token,
|
||||
sort_by,
|
||||
}: List_api_calls_for_user_params): Promise<List_api_calls_for_user_return> {
|
||||
const url = `/users/${id}/api-calls?limit=${limit}&page_token=${page_token}&sort_by=${sort_by}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as List_api_calls_for_user_return;
|
||||
return result;
|
||||
}
|
32
src/api/api-calls/list_async_operations.ts
Normal file
32
src/api/api-calls/list_async_operations.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { AsyncApiCallResultsPage_type, Error_type } from '../../models.js';
|
||||
|
||||
interface List_async_operations_params {
|
||||
limit: string;
|
||||
page_token: string;
|
||||
sort_by: string;
|
||||
status: string;
|
||||
}
|
||||
|
||||
type List_async_operations_return = AsyncApiCallResultsPage_type | Error_type;
|
||||
|
||||
export default async function list_async_operations({
|
||||
limit,
|
||||
page_token,
|
||||
sort_by,
|
||||
status,
|
||||
}: List_async_operations_params): Promise<List_async_operations_return> {
|
||||
const url = `/async/operations?limit=${limit}&page_token=${page_token}&sort_by=${sort_by}&status=${status}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as List_async_operations_return;
|
||||
return result;
|
||||
}
|
30
src/api/api-calls/user_list_api_calls.ts
Normal file
30
src/api/api-calls/user_list_api_calls.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { ApiCallWithPriceResultsPage_type, Error_type } from '../../models.js';
|
||||
|
||||
interface User_list_api_calls_params {
|
||||
limit: string;
|
||||
page_token: string;
|
||||
sort_by: string;
|
||||
}
|
||||
|
||||
type User_list_api_calls_return = ApiCallWithPriceResultsPage_type | Error_type;
|
||||
|
||||
export default async function user_list_api_calls({
|
||||
limit,
|
||||
page_token,
|
||||
sort_by,
|
||||
}: User_list_api_calls_params): Promise<User_list_api_calls_return> {
|
||||
const url = `/user/api-calls?limit=${limit}&page_token=${page_token}&sort_by=${sort_by}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as User_list_api_calls_return;
|
||||
return result;
|
||||
}
|
20
src/api/api-tokens/create_api_token_for_user.ts
Normal file
20
src/api/api-tokens/create_api_token_for_user.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { ApiToken_type, Error_type } from '../../models.js';
|
||||
|
||||
type Create_api_token_for_user_return = ApiToken_type | Error_type;
|
||||
|
||||
export default async function create_api_token_for_user(): Promise<Create_api_token_for_user_return> {
|
||||
const url = `/user/api-tokens`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Create_api_token_for_user_return;
|
||||
return result;
|
||||
}
|
26
src/api/api-tokens/delete_api_token_for_user.ts
Normal file
26
src/api/api-tokens/delete_api_token_for_user.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { Error_type } from '../../models.js';
|
||||
|
||||
interface Delete_api_token_for_user_params {
|
||||
token: string;
|
||||
}
|
||||
|
||||
type Delete_api_token_for_user_return = Error_type;
|
||||
|
||||
export default async function delete_api_token_for_user({
|
||||
token,
|
||||
}: Delete_api_token_for_user_params): Promise<Delete_api_token_for_user_return> {
|
||||
const url = `/user/api-tokens/${token}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Delete_api_token_for_user_return;
|
||||
return result;
|
||||
}
|
26
src/api/api-tokens/get_api_token_for_user.ts
Normal file
26
src/api/api-tokens/get_api_token_for_user.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { ApiToken_type, Error_type } from '../../models.js';
|
||||
|
||||
interface Get_api_token_for_user_params {
|
||||
token: string;
|
||||
}
|
||||
|
||||
type Get_api_token_for_user_return = ApiToken_type | Error_type;
|
||||
|
||||
export default async function get_api_token_for_user({
|
||||
token,
|
||||
}: Get_api_token_for_user_params): Promise<Get_api_token_for_user_return> {
|
||||
const url = `/user/api-tokens/${token}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Get_api_token_for_user_return;
|
||||
return result;
|
||||
}
|
30
src/api/api-tokens/list_api_tokens_for_user.ts
Normal file
30
src/api/api-tokens/list_api_tokens_for_user.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { ApiTokenResultsPage_type, Error_type } from '../../models.js';
|
||||
|
||||
interface List_api_tokens_for_user_params {
|
||||
limit: string;
|
||||
page_token: string;
|
||||
sort_by: string;
|
||||
}
|
||||
|
||||
type List_api_tokens_for_user_return = ApiTokenResultsPage_type | Error_type;
|
||||
|
||||
export default async function list_api_tokens_for_user({
|
||||
limit,
|
||||
page_token,
|
||||
sort_by,
|
||||
}: List_api_tokens_for_user_params): Promise<List_api_tokens_for_user_return> {
|
||||
const url = `/user/api-tokens?limit=${limit}&page_token=${page_token}&sort_by=${sort_by}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as List_api_tokens_for_user_return;
|
||||
return result;
|
||||
}
|
31
src/api/file/create_file_conversion.ts
Normal file
31
src/api/file/create_file_conversion.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { FileConversion_type, Error_type } from '../../models.js';
|
||||
|
||||
interface Create_file_conversion_params {
|
||||
output_format: string;
|
||||
src_format: string;
|
||||
body: string;
|
||||
}
|
||||
|
||||
type Create_file_conversion_return = FileConversion_type | Error_type;
|
||||
|
||||
export default async function create_file_conversion({
|
||||
output_format,
|
||||
src_format,
|
||||
body,
|
||||
}: Create_file_conversion_params): Promise<Create_file_conversion_return> {
|
||||
const url = `/file/conversion/${src_format}/${output_format}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Create_file_conversion_return;
|
||||
return result;
|
||||
}
|
31
src/api/file/create_file_density.ts
Normal file
31
src/api/file/create_file_density.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { FileDensity_type, Error_type } from '../../models.js';
|
||||
|
||||
interface Create_file_density_params {
|
||||
material_mass: string;
|
||||
src_format: string;
|
||||
body: string;
|
||||
}
|
||||
|
||||
type Create_file_density_return = FileDensity_type | Error_type;
|
||||
|
||||
export default async function create_file_density({
|
||||
material_mass,
|
||||
src_format,
|
||||
body,
|
||||
}: Create_file_density_params): Promise<Create_file_density_return> {
|
||||
const url = `/file/density?material_mass=${material_mass}&src_format=${src_format}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Create_file_density_return;
|
||||
return result;
|
||||
}
|
31
src/api/file/create_file_execution.ts
Normal file
31
src/api/file/create_file_execution.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { CodeOutput_type, Error_type } from '../../models.js';
|
||||
|
||||
interface Create_file_execution_params {
|
||||
lang: string;
|
||||
output: string;
|
||||
body: string;
|
||||
}
|
||||
|
||||
type Create_file_execution_return = CodeOutput_type | Error_type;
|
||||
|
||||
export default async function create_file_execution({
|
||||
lang,
|
||||
output,
|
||||
body,
|
||||
}: Create_file_execution_params): Promise<Create_file_execution_return> {
|
||||
const url = `/file/execute/${lang}?output=${output}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Create_file_execution_return;
|
||||
return result;
|
||||
}
|
31
src/api/file/create_file_mass.ts
Normal file
31
src/api/file/create_file_mass.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { FileMass_type, Error_type } from '../../models.js';
|
||||
|
||||
interface Create_file_mass_params {
|
||||
material_density: string;
|
||||
src_format: string;
|
||||
body: string;
|
||||
}
|
||||
|
||||
type Create_file_mass_return = FileMass_type | Error_type;
|
||||
|
||||
export default async function create_file_mass({
|
||||
material_density,
|
||||
src_format,
|
||||
body,
|
||||
}: Create_file_mass_params): Promise<Create_file_mass_return> {
|
||||
const url = `/file/mass?material_density=${material_density}&src_format=${src_format}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Create_file_mass_return;
|
||||
return result;
|
||||
}
|
29
src/api/file/create_file_volume.ts
Normal file
29
src/api/file/create_file_volume.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { FileVolume_type, Error_type } from '../../models.js';
|
||||
|
||||
interface Create_file_volume_params {
|
||||
src_format: string;
|
||||
body: string;
|
||||
}
|
||||
|
||||
type Create_file_volume_return = FileVolume_type | Error_type;
|
||||
|
||||
export default async function create_file_volume({
|
||||
src_format,
|
||||
body,
|
||||
}: Create_file_volume_params): Promise<Create_file_volume_return> {
|
||||
const url = `/file/volume?src_format=${src_format}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Create_file_volume_return;
|
||||
return result;
|
||||
}
|
26
src/api/file/get_file_conversion.ts
Normal file
26
src/api/file/get_file_conversion.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { AsyncApiCallOutput_type, Error_type } from '../../models.js';
|
||||
|
||||
interface Get_file_conversion_params {
|
||||
id: string;
|
||||
}
|
||||
|
||||
type Get_file_conversion_return = AsyncApiCallOutput_type | Error_type;
|
||||
|
||||
export default async function get_file_conversion({
|
||||
id,
|
||||
}: Get_file_conversion_params): Promise<Get_file_conversion_return> {
|
||||
const url = `/file/conversions/${id}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Get_file_conversion_return;
|
||||
return result;
|
||||
}
|
26
src/api/file/get_file_conversion_for_user.ts
Normal file
26
src/api/file/get_file_conversion_for_user.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { AsyncApiCallOutput_type, Error_type } from '../../models.js';
|
||||
|
||||
interface Get_file_conversion_for_user_params {
|
||||
id: string;
|
||||
}
|
||||
|
||||
type Get_file_conversion_for_user_return = AsyncApiCallOutput_type | Error_type;
|
||||
|
||||
export default async function get_file_conversion_for_user({
|
||||
id,
|
||||
}: Get_file_conversion_for_user_params): Promise<Get_file_conversion_for_user_return> {
|
||||
const url = `/user/file/conversions/${id}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Get_file_conversion_for_user_return;
|
||||
return result;
|
||||
}
|
20
src/api/meta/get_metadata.ts
Normal file
20
src/api/meta/get_metadata.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { Metadata_type, Error_type } from '../../models.js';
|
||||
|
||||
type Get_metadata_return = Metadata_type | Error_type;
|
||||
|
||||
export default async function get_metadata(): Promise<Get_metadata_return> {
|
||||
const url = `/_meta/info`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Get_metadata_return;
|
||||
return result;
|
||||
}
|
20
src/api/meta/get_schema.ts
Normal file
20
src/api/meta/get_schema.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { Error_type } from '../../models.js';
|
||||
|
||||
type Get_schema_return = Error_type;
|
||||
|
||||
export default async function get_schema(): Promise<Get_schema_return> {
|
||||
const url = `/`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Get_schema_return;
|
||||
return result;
|
||||
}
|
20
src/api/meta/ping.ts
Normal file
20
src/api/meta/ping.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { Pong_type, Error_type } from '../../models.js';
|
||||
|
||||
type Ping_return = Pong_type | Error_type;
|
||||
|
||||
export default async function ping(): Promise<Ping_return> {
|
||||
const url = `/ping`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Ping_return;
|
||||
return result;
|
||||
}
|
20
src/api/oauth2/device_access_token.ts
Normal file
20
src/api/oauth2/device_access_token.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import fetch from 'node-fetch';
|
||||
import {} from '../../models.js';
|
||||
|
||||
type Device_access_token_return = any;
|
||||
|
||||
export default async function device_access_token(): Promise<Device_access_token_return> {
|
||||
const url = `/oauth2/device/token`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Device_access_token_return;
|
||||
return result;
|
||||
}
|
20
src/api/oauth2/device_auth_confirm.ts
Normal file
20
src/api/oauth2/device_auth_confirm.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { Error_type } from '../../models.js';
|
||||
|
||||
type Device_auth_confirm_return = Error_type;
|
||||
|
||||
export default async function device_auth_confirm(): Promise<Device_auth_confirm_return> {
|
||||
const url = `/oauth2/device/confirm`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Device_auth_confirm_return;
|
||||
return result;
|
||||
}
|
20
src/api/oauth2/device_auth_request.ts
Normal file
20
src/api/oauth2/device_auth_request.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import fetch from 'node-fetch';
|
||||
import {} from '../../models.js';
|
||||
|
||||
type Device_auth_request_return = any;
|
||||
|
||||
export default async function device_auth_request(): Promise<Device_auth_request_return> {
|
||||
const url = `/oauth2/device/auth`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Device_auth_request_return;
|
||||
return result;
|
||||
}
|
26
src/api/oauth2/device_auth_verify.ts
Normal file
26
src/api/oauth2/device_auth_verify.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { Error_type } from '../../models.js';
|
||||
|
||||
interface Device_auth_verify_params {
|
||||
user_code: string;
|
||||
}
|
||||
|
||||
type Device_auth_verify_return = Error_type;
|
||||
|
||||
export default async function device_auth_verify({
|
||||
user_code,
|
||||
}: Device_auth_verify_params): Promise<Device_auth_verify_return> {
|
||||
const url = `/oauth2/device/verify?user_code=${user_code}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Device_auth_verify_return;
|
||||
return result;
|
||||
}
|
31
src/api/oauth2/listen_oauth2_provider_callback.ts
Normal file
31
src/api/oauth2/listen_oauth2_provider_callback.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { Error_type } from '../../models.js';
|
||||
|
||||
interface Listen_oauth2_provider_callback_params {
|
||||
provider: string;
|
||||
code: string;
|
||||
state: string;
|
||||
}
|
||||
|
||||
type Listen_oauth2_provider_callback_return = Error_type;
|
||||
|
||||
export default async function listen_oauth2_provider_callback({
|
||||
provider,
|
||||
code,
|
||||
state,
|
||||
}: Listen_oauth2_provider_callback_params): Promise<Listen_oauth2_provider_callback_return> {
|
||||
const url = `/oauth2/provider/${provider}/callback?code=${code}&state=${state}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result =
|
||||
(await response.json()) as Listen_oauth2_provider_callback_return;
|
||||
return result;
|
||||
}
|
29
src/api/oauth2/listen_oauth2_provider_consent.ts
Normal file
29
src/api/oauth2/listen_oauth2_provider_consent.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { OAuth2ClientInfo_type, Error_type } from '../../models.js';
|
||||
|
||||
interface Listen_oauth2_provider_consent_params {
|
||||
provider: string;
|
||||
callback_url: string;
|
||||
}
|
||||
|
||||
type Listen_oauth2_provider_consent_return = OAuth2ClientInfo_type | Error_type;
|
||||
|
||||
export default async function listen_oauth2_provider_consent({
|
||||
provider,
|
||||
callback_url,
|
||||
}: Listen_oauth2_provider_consent_params): Promise<Listen_oauth2_provider_consent_return> {
|
||||
const url = `/oauth2/provider/${provider}/consent?callback_url=${callback_url}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result =
|
||||
(await response.json()) as Listen_oauth2_provider_consent_return;
|
||||
return result;
|
||||
}
|
21
src/api/payments/create_payment_information_for_user.ts
Normal file
21
src/api/payments/create_payment_information_for_user.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { Customer_type, Error_type } from '../../models.js';
|
||||
|
||||
type Create_payment_information_for_user_return = Customer_type | Error_type;
|
||||
|
||||
export default async function create_payment_information_for_user(): Promise<Create_payment_information_for_user_return> {
|
||||
const url = `/user/payment`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result =
|
||||
(await response.json()) as Create_payment_information_for_user_return;
|
||||
return result;
|
||||
}
|
21
src/api/payments/create_payment_intent_for_user.ts
Normal file
21
src/api/payments/create_payment_intent_for_user.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { PaymentIntent_type, Error_type } from '../../models.js';
|
||||
|
||||
type Create_payment_intent_for_user_return = PaymentIntent_type | Error_type;
|
||||
|
||||
export default async function create_payment_intent_for_user(): Promise<Create_payment_intent_for_user_return> {
|
||||
const url = `/user/payment/intent`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result =
|
||||
(await response.json()) as Create_payment_intent_for_user_return;
|
||||
return result;
|
||||
}
|
21
src/api/payments/delete_payment_information_for_user.ts
Normal file
21
src/api/payments/delete_payment_information_for_user.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { Error_type } from '../../models.js';
|
||||
|
||||
type Delete_payment_information_for_user_return = Error_type;
|
||||
|
||||
export default async function delete_payment_information_for_user(): Promise<Delete_payment_information_for_user_return> {
|
||||
const url = `/user/payment`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result =
|
||||
(await response.json()) as Delete_payment_information_for_user_return;
|
||||
return result;
|
||||
}
|
27
src/api/payments/delete_payment_method_for_user.ts
Normal file
27
src/api/payments/delete_payment_method_for_user.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { Error_type } from '../../models.js';
|
||||
|
||||
interface Delete_payment_method_for_user_params {
|
||||
id: string;
|
||||
}
|
||||
|
||||
type Delete_payment_method_for_user_return = Error_type;
|
||||
|
||||
export default async function delete_payment_method_for_user({
|
||||
id,
|
||||
}: Delete_payment_method_for_user_params): Promise<Delete_payment_method_for_user_return> {
|
||||
const url = `/user/payment/methods/${id}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result =
|
||||
(await response.json()) as Delete_payment_method_for_user_return;
|
||||
return result;
|
||||
}
|
20
src/api/payments/get_payment_balance_for_user.ts
Normal file
20
src/api/payments/get_payment_balance_for_user.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { CustomerBalance_type, Error_type } from '../../models.js';
|
||||
|
||||
type Get_payment_balance_for_user_return = CustomerBalance_type | Error_type;
|
||||
|
||||
export default async function get_payment_balance_for_user(): Promise<Get_payment_balance_for_user_return> {
|
||||
const url = `/user/payment/balance`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Get_payment_balance_for_user_return;
|
||||
return result;
|
||||
}
|
21
src/api/payments/get_payment_information_for_user.ts
Normal file
21
src/api/payments/get_payment_information_for_user.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { Customer_type, Error_type } from '../../models.js';
|
||||
|
||||
type Get_payment_information_for_user_return = Customer_type | Error_type;
|
||||
|
||||
export default async function get_payment_information_for_user(): Promise<Get_payment_information_for_user_return> {
|
||||
const url = `/user/payment`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result =
|
||||
(await response.json()) as Get_payment_information_for_user_return;
|
||||
return result;
|
||||
}
|
20
src/api/payments/list_invoices_for_user.ts
Normal file
20
src/api/payments/list_invoices_for_user.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { Invoice_type, Error_type } from '../../models.js';
|
||||
|
||||
type List_invoices_for_user_return = Invoice_type[] | Error_type;
|
||||
|
||||
export default async function list_invoices_for_user(): Promise<List_invoices_for_user_return> {
|
||||
const url = `/user/payment/invoices`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as List_invoices_for_user_return;
|
||||
return result;
|
||||
}
|
21
src/api/payments/list_payment_methods_for_user.ts
Normal file
21
src/api/payments/list_payment_methods_for_user.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { PaymentMethod_type, Error_type } from '../../models.js';
|
||||
|
||||
type List_payment_methods_for_user_return = PaymentMethod_type[] | Error_type;
|
||||
|
||||
export default async function list_payment_methods_for_user(): Promise<List_payment_methods_for_user_return> {
|
||||
const url = `/user/payment/methods`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result =
|
||||
(await response.json()) as List_payment_methods_for_user_return;
|
||||
return result;
|
||||
}
|
21
src/api/payments/update_payment_information_for_user.ts
Normal file
21
src/api/payments/update_payment_information_for_user.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { Customer_type, Error_type } from '../../models.js';
|
||||
|
||||
type Update_payment_information_for_user_return = Customer_type | Error_type;
|
||||
|
||||
export default async function update_payment_information_for_user(): Promise<Update_payment_information_for_user_return> {
|
||||
const url = `/user/payment`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result =
|
||||
(await response.json()) as Update_payment_information_for_user_return;
|
||||
return result;
|
||||
}
|
26
src/api/sessions/get_session_for_user.ts
Normal file
26
src/api/sessions/get_session_for_user.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { Session_type, Error_type } from '../../models.js';
|
||||
|
||||
interface Get_session_for_user_params {
|
||||
token: string;
|
||||
}
|
||||
|
||||
type Get_session_for_user_return = Session_type | Error_type;
|
||||
|
||||
export default async function get_session_for_user({
|
||||
token,
|
||||
}: Get_session_for_user_params): Promise<Get_session_for_user_return> {
|
||||
const url = `/user/session/${token}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Get_session_for_user_return;
|
||||
return result;
|
||||
}
|
30
src/api/unit/create_unit_conversion.ts
Normal file
30
src/api/unit/create_unit_conversion.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { UnitConversion_type, Error_type } from '../../models.js';
|
||||
|
||||
interface Create_unit_conversion_params {
|
||||
output_format: string;
|
||||
src_format: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
type Create_unit_conversion_return = UnitConversion_type | Error_type;
|
||||
|
||||
export default async function create_unit_conversion({
|
||||
output_format,
|
||||
src_format,
|
||||
value,
|
||||
}: Create_unit_conversion_params): Promise<Create_unit_conversion_return> {
|
||||
const url = `/unit/conversion/${src_format}/${output_format}?value=${value}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Create_unit_conversion_return;
|
||||
return result;
|
||||
}
|
20
src/api/users/delete_user_self.ts
Normal file
20
src/api/users/delete_user_self.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { Error_type } from '../../models.js';
|
||||
|
||||
type Delete_user_self_return = Error_type;
|
||||
|
||||
export default async function delete_user_self(): Promise<Delete_user_self_return> {
|
||||
const url = `/user`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Delete_user_self_return;
|
||||
return result;
|
||||
}
|
26
src/api/users/get_user.ts
Normal file
26
src/api/users/get_user.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { User_type, Error_type } from '../../models.js';
|
||||
|
||||
interface Get_user_params {
|
||||
id: string;
|
||||
}
|
||||
|
||||
type Get_user_return = User_type | Error_type;
|
||||
|
||||
export default async function get_user({
|
||||
id,
|
||||
}: Get_user_params): Promise<Get_user_return> {
|
||||
const url = `/users/${id}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Get_user_return;
|
||||
return result;
|
||||
}
|
26
src/api/users/get_user_extended.ts
Normal file
26
src/api/users/get_user_extended.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { ExtendedUser_type, Error_type } from '../../models.js';
|
||||
|
||||
interface Get_user_extended_params {
|
||||
id: string;
|
||||
}
|
||||
|
||||
type Get_user_extended_return = ExtendedUser_type | Error_type;
|
||||
|
||||
export default async function get_user_extended({
|
||||
id,
|
||||
}: Get_user_extended_params): Promise<Get_user_extended_return> {
|
||||
const url = `/users-extended/${id}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Get_user_extended_return;
|
||||
return result;
|
||||
}
|
20
src/api/users/get_user_self.ts
Normal file
20
src/api/users/get_user_self.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { User_type, Error_type } from '../../models.js';
|
||||
|
||||
type Get_user_self_return = User_type | Error_type;
|
||||
|
||||
export default async function get_user_self(): Promise<Get_user_self_return> {
|
||||
const url = `/user`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Get_user_self_return;
|
||||
return result;
|
||||
}
|
20
src/api/users/get_user_self_extended.ts
Normal file
20
src/api/users/get_user_self_extended.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { ExtendedUser_type, Error_type } from '../../models.js';
|
||||
|
||||
type Get_user_self_extended_return = ExtendedUser_type | Error_type;
|
||||
|
||||
export default async function get_user_self_extended(): Promise<Get_user_self_extended_return> {
|
||||
const url = `/user/extended`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Get_user_self_extended_return;
|
||||
return result;
|
||||
}
|
30
src/api/users/list_users.ts
Normal file
30
src/api/users/list_users.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { UserResultsPage_type, Error_type } from '../../models.js';
|
||||
|
||||
interface List_users_params {
|
||||
limit: string;
|
||||
page_token: string;
|
||||
sort_by: string;
|
||||
}
|
||||
|
||||
type List_users_return = UserResultsPage_type | Error_type;
|
||||
|
||||
export default async function list_users({
|
||||
limit,
|
||||
page_token,
|
||||
sort_by,
|
||||
}: List_users_params): Promise<List_users_return> {
|
||||
const url = `/users?limit=${limit}&page_token=${page_token}&sort_by=${sort_by}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as List_users_return;
|
||||
return result;
|
||||
}
|
30
src/api/users/list_users_extended.ts
Normal file
30
src/api/users/list_users_extended.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { ExtendedUserResultsPage_type, Error_type } from '../../models.js';
|
||||
|
||||
interface List_users_extended_params {
|
||||
limit: string;
|
||||
page_token: string;
|
||||
sort_by: string;
|
||||
}
|
||||
|
||||
type List_users_extended_return = ExtendedUserResultsPage_type | Error_type;
|
||||
|
||||
export default async function list_users_extended({
|
||||
limit,
|
||||
page_token,
|
||||
sort_by,
|
||||
}: List_users_extended_params): Promise<List_users_extended_return> {
|
||||
const url = `/users-extended?limit=${limit}&page_token=${page_token}&sort_by=${sort_by}`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as List_users_extended_return;
|
||||
return result;
|
||||
}
|
20
src/api/users/update_user_self.ts
Normal file
20
src/api/users/update_user_self.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { User_type, Error_type } from '../../models.js';
|
||||
|
||||
type Update_user_self_return = User_type | Error_type;
|
||||
|
||||
export default async function update_user_self(): Promise<Update_user_self_return> {
|
||||
const url = `/user`;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || '';
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as Update_user_self_return;
|
||||
return result;
|
||||
}
|
219
src/apiGen.ts
Normal file
219
src/apiGen.ts
Normal file
@ -0,0 +1,219 @@
|
||||
import fsp from 'node:fs/promises';
|
||||
import { OpenAPIV3 } from 'openapi-types';
|
||||
|
||||
export default async function apiGen(lookup: any) {
|
||||
const spec: OpenAPIV3.Document = JSON.parse(
|
||||
await fsp.readFile('./spec.json', 'utf8'),
|
||||
);
|
||||
const tags = spec.tags;
|
||||
await Promise.allSettled(
|
||||
tags.map(({ name }) => fsp.mkdir(`./src/api/${name}`)),
|
||||
);
|
||||
const operationIds: string[] = [];
|
||||
const operations: {
|
||||
[key: string]: {
|
||||
specSection: OpenAPIV3.PathItemObject['post' | 'get' | 'put' | 'delete'];
|
||||
path: string;
|
||||
method: string;
|
||||
};
|
||||
} = {};
|
||||
Object.entries(spec.paths).forEach(([path, pathValue]) => {
|
||||
Object.entries(pathValue).forEach(([method, _methodValue]) => {
|
||||
const methodValue = _methodValue as OpenAPIV3.PathItemObject[
|
||||
| 'post'
|
||||
| 'get'
|
||||
| 'put'
|
||||
| 'delete'];
|
||||
const operationId = (methodValue as any).operationId;
|
||||
if (!operationId) {
|
||||
throw `no operationId for ${path} ${method}`;
|
||||
}
|
||||
operations[operationId] = {
|
||||
path,
|
||||
method,
|
||||
specSection: methodValue,
|
||||
};
|
||||
operationIds.push(operationId);
|
||||
});
|
||||
});
|
||||
const indexFile: {
|
||||
[tag: string]: {
|
||||
importsStr: string[];
|
||||
exportsStr: string[];
|
||||
};
|
||||
} = {};
|
||||
const writePromises = Object.entries(operations).map(async ([operationId, operation]) => {
|
||||
if ('hidden' === (operation.specSection as any).tags[0]) {
|
||||
return;
|
||||
}
|
||||
let template: string = await fsp.readFile('./src/template.ts.txt', 'utf8');
|
||||
const path = operation.path;
|
||||
const params = operation.specSection
|
||||
.parameters as OpenAPIV3.ParameterObject[];
|
||||
template = template.replaceAll(',', ',');
|
||||
const inputTypes: string[] = [];
|
||||
const inputParams: string[] = [];
|
||||
let urlPathParams: string[] = path.split('/');
|
||||
const urlQueryParams: string[] = [];
|
||||
(params || []).forEach(({ name, in: _in }) => {
|
||||
inputTypes.push(`${name}: string`);
|
||||
if (!name) {
|
||||
throw 'no name for param';
|
||||
}
|
||||
inputParams.push(name);
|
||||
if (_in === 'path') {
|
||||
urlPathParams = urlPathParams.map((p) => {
|
||||
if (p === `{${name}}`) {
|
||||
return `\${${name}}`;
|
||||
}
|
||||
return p;
|
||||
});
|
||||
} else {
|
||||
urlQueryParams.push(`${name}=\${${name}}`);
|
||||
}
|
||||
});
|
||||
const templateUrlPath = wrapInBacktics(
|
||||
`${urlPathParams.join('/')}${
|
||||
urlQueryParams.length ? `?${urlQueryParams.join('&')}` : ''
|
||||
}`,
|
||||
);
|
||||
const requestBody = operation.specSection
|
||||
?.requestBody as OpenAPIV3.ResponseObject;
|
||||
|
||||
if (requestBody?.content?.['application/octet-stream']) {
|
||||
const schema = requestBody.content['application/octet-stream']
|
||||
.schema as OpenAPIV3.SchemaObject;
|
||||
if (schema?.type !== 'string') {
|
||||
throw 'requestBody type not implemented';
|
||||
}
|
||||
inputTypes.push('body: string');
|
||||
inputParams.push('body');
|
||||
template = template.replaceAll("body: 'BODY'", 'body');
|
||||
} else {
|
||||
template = template.replaceAll(/body: 'BODY'.+/g, '');
|
||||
}
|
||||
|
||||
if (!inputParams.length) {
|
||||
template = replacer(template, [
|
||||
[/interface FunctionNameParams(.|\n)+?}/g, ''],
|
||||
[/functionNameParams: FunctionNameParams.+/g, ''],
|
||||
]);
|
||||
}
|
||||
|
||||
const importedTypes: string[] = [];
|
||||
Object.values(operation.specSection?.responses).forEach((response) => {
|
||||
const schema = (response as any)?.content?.['application/json']
|
||||
?.schema as OpenAPIV3.SchemaObject;
|
||||
if (!schema) {
|
||||
let ref = (response as any)?.$ref || '';
|
||||
ref = ref.replace('responses', 'schemas');
|
||||
const typeReference = lookup[ref];
|
||||
|
||||
if (!importedTypes.includes(typeReference) && ref) {
|
||||
importedTypes.push(typeReference);
|
||||
}
|
||||
} else if ((response as any)?.content['application/json']?.schema?.$ref) {
|
||||
const ref = (response as any)?.content['application/json']?.schema
|
||||
?.$ref;
|
||||
const typeReference = lookup[ref];
|
||||
if (!importedTypes.includes(typeReference)) {
|
||||
importedTypes.push(typeReference);
|
||||
}
|
||||
} else if (Object.keys(schema).length === 0) {
|
||||
// do nothing
|
||||
} else if (schema.type === 'array') {
|
||||
const items = schema.items as OpenAPIV3.SchemaObject;
|
||||
if ((items as any).$ref) {
|
||||
const typeReference = lookup[(items as any).$ref];
|
||||
if (!importedTypes.includes(typeReference + '[]')) {
|
||||
importedTypes.push(typeReference + '[]');
|
||||
}
|
||||
} else {
|
||||
throw 'not implemented';
|
||||
}
|
||||
} else {
|
||||
console.log(schema);
|
||||
throw 'not implemented';
|
||||
}
|
||||
});
|
||||
|
||||
const returnTyping = `type ${FC(operationId)}_return = ${
|
||||
importedTypes.length ? importedTypes.join(' | ') : 'any'
|
||||
}`;
|
||||
|
||||
template = replacer(template, [
|
||||
[/interface FunctionNameReturn(.|\n)+?}/g, returnTyping],
|
||||
[`'string' + functionNameParams.exampleParam`, templateUrlPath],
|
||||
[`functionNameParams:`, `{${inputParams.filter((a) => a).join(', ')}}:`],
|
||||
[`exampleParam: string`, inputTypes.join('; ')],
|
||||
["method: 'METHOD'", `method: 'POST'`],
|
||||
['function functionName', `function ${operationId}`],
|
||||
['FunctionNameReturn', `${FC(operationId)}_return`],
|
||||
['FunctionNameParams', `${FC(operationId)}_params`],
|
||||
[
|
||||
"import * as types from './src/models.ts';",
|
||||
`import {${importedTypes
|
||||
.map((a) => (a || '').replaceAll('[', '').replaceAll(']', ''))
|
||||
.join(', ')}} from '../../models.js';`,
|
||||
],
|
||||
]);
|
||||
|
||||
const tag = operation.specSection?.tags?.[0] || 'err';
|
||||
const safeTag = tag.replaceAll('-', '_');
|
||||
if (!indexFile[safeTag]) {
|
||||
indexFile[safeTag] = {
|
||||
importsStr: [],
|
||||
exportsStr: [],
|
||||
};
|
||||
}
|
||||
indexFile[safeTag].importsStr.push(
|
||||
`import ${operationId} from './api/${tag}/${operationId}.js';`,
|
||||
);
|
||||
indexFile[safeTag].exportsStr.push(operationId)
|
||||
return fsp.writeFile(`./src/api/${tag}/${operationId}.ts`, template, 'utf8');
|
||||
});
|
||||
await Promise.all(writePromises);
|
||||
console.log('HEYY yo')
|
||||
let indexFileString = ''
|
||||
Object.entries(indexFile).forEach(([tag, { importsStr: imports, exportsStr: exports }]) => {
|
||||
indexFileString += imports.join('\n') + '\n';
|
||||
indexFileString += `export const ${tag} = { ${exports.join(', ')} };\n\n`;
|
||||
})
|
||||
console.log('hmm', indexFile, indexFileString);
|
||||
await fsp.writeFile(`./src/main.ts`, indexFileString, 'utf8');
|
||||
}
|
||||
|
||||
function wrapInBacktics(str: string) {
|
||||
return `\`${str}\``;
|
||||
}
|
||||
|
||||
function replacer(
|
||||
template: string,
|
||||
replaceList: (
|
||||
| [string | RegExp, string]
|
||||
| [string | RegExp, string, boolean]
|
||||
)[],
|
||||
): string {
|
||||
let result = template;
|
||||
replaceList.forEach(([search, newVal, debug]) => {
|
||||
if (debug) {
|
||||
const newTemplate = result.replace(search, newVal);
|
||||
console.log({ old: result, newTemplate });
|
||||
}
|
||||
result = result.replaceAll(search, newVal);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export function isObj(obj: any) {
|
||||
return (
|
||||
typeof obj === 'object' &&
|
||||
obj !== null &&
|
||||
!Array.isArray(obj) &&
|
||||
Object.keys(obj).length
|
||||
);
|
||||
}
|
||||
|
||||
function FC(str: string): string {
|
||||
return str.charAt(0).toUpperCase() + str.slice(1);
|
||||
}
|
112
src/main.ts
Normal file
112
src/main.ts
Normal file
@ -0,0 +1,112 @@
|
||||
import get_schema from './api/meta/get_schema.js';
|
||||
import ping from './api/meta/ping.js';
|
||||
import get_metadata from './api/meta/get_metadata.js';
|
||||
export const meta = { get_schema, ping, get_metadata };
|
||||
|
||||
import get_api_call_metrics from './api/api-calls/get_api_call_metrics.js';
|
||||
import get_api_call from './api/api-calls/get_api_call.js';
|
||||
import get_async_operation from './api/api-calls/get_async_operation.js';
|
||||
import list_api_calls from './api/api-calls/list_api_calls.js';
|
||||
import list_async_operations from './api/api-calls/list_async_operations.js';
|
||||
import user_list_api_calls from './api/api-calls/user_list_api_calls.js';
|
||||
import get_api_call_for_user from './api/api-calls/get_api_call_for_user.js';
|
||||
import list_api_calls_for_user from './api/api-calls/list_api_calls_for_user.js';
|
||||
export const api_calls = {
|
||||
get_api_call_metrics,
|
||||
get_api_call,
|
||||
get_async_operation,
|
||||
list_api_calls,
|
||||
list_async_operations,
|
||||
user_list_api_calls,
|
||||
get_api_call_for_user,
|
||||
list_api_calls_for_user,
|
||||
};
|
||||
|
||||
import get_file_conversion from './api/file/get_file_conversion.js';
|
||||
import create_file_conversion from './api/file/create_file_conversion.js';
|
||||
import create_file_execution from './api/file/create_file_execution.js';
|
||||
import create_file_mass from './api/file/create_file_mass.js';
|
||||
import create_file_volume from './api/file/create_file_volume.js';
|
||||
import create_file_density from './api/file/create_file_density.js';
|
||||
import get_file_conversion_for_user from './api/file/get_file_conversion_for_user.js';
|
||||
export const file = {
|
||||
get_file_conversion,
|
||||
create_file_conversion,
|
||||
create_file_execution,
|
||||
create_file_mass,
|
||||
create_file_volume,
|
||||
create_file_density,
|
||||
get_file_conversion_for_user,
|
||||
};
|
||||
|
||||
import device_auth_request from './api/oauth2/device_auth_request.js';
|
||||
import device_auth_confirm from './api/oauth2/device_auth_confirm.js';
|
||||
import device_access_token from './api/oauth2/device_access_token.js';
|
||||
import device_auth_verify from './api/oauth2/device_auth_verify.js';
|
||||
import listen_oauth2_provider_callback from './api/oauth2/listen_oauth2_provider_callback.js';
|
||||
import listen_oauth2_provider_consent from './api/oauth2/listen_oauth2_provider_consent.js';
|
||||
export const oauth2 = {
|
||||
device_auth_request,
|
||||
device_auth_confirm,
|
||||
device_access_token,
|
||||
device_auth_verify,
|
||||
listen_oauth2_provider_callback,
|
||||
listen_oauth2_provider_consent,
|
||||
};
|
||||
|
||||
import create_unit_conversion from './api/unit/create_unit_conversion.js';
|
||||
export const unit = { create_unit_conversion };
|
||||
|
||||
import delete_user_self from './api/users/delete_user_self.js';
|
||||
import update_user_self from './api/users/update_user_self.js';
|
||||
import get_user_self from './api/users/get_user_self.js';
|
||||
import get_user_self_extended from './api/users/get_user_self_extended.js';
|
||||
import list_users from './api/users/list_users.js';
|
||||
import list_users_extended from './api/users/list_users_extended.js';
|
||||
import get_user_extended from './api/users/get_user_extended.js';
|
||||
import get_user from './api/users/get_user.js';
|
||||
export const users = {
|
||||
delete_user_self,
|
||||
update_user_self,
|
||||
get_user_self,
|
||||
get_user_self_extended,
|
||||
list_users,
|
||||
list_users_extended,
|
||||
get_user_extended,
|
||||
get_user,
|
||||
};
|
||||
|
||||
import create_api_token_for_user from './api/api-tokens/create_api_token_for_user.js';
|
||||
import list_api_tokens_for_user from './api/api-tokens/list_api_tokens_for_user.js';
|
||||
import delete_api_token_for_user from './api/api-tokens/delete_api_token_for_user.js';
|
||||
import get_api_token_for_user from './api/api-tokens/get_api_token_for_user.js';
|
||||
export const api_tokens = {
|
||||
create_api_token_for_user,
|
||||
list_api_tokens_for_user,
|
||||
delete_api_token_for_user,
|
||||
get_api_token_for_user,
|
||||
};
|
||||
|
||||
import delete_payment_information_for_user from './api/payments/delete_payment_information_for_user.js';
|
||||
import get_payment_information_for_user from './api/payments/get_payment_information_for_user.js';
|
||||
import create_payment_information_for_user from './api/payments/create_payment_information_for_user.js';
|
||||
import update_payment_information_for_user from './api/payments/update_payment_information_for_user.js';
|
||||
import create_payment_intent_for_user from './api/payments/create_payment_intent_for_user.js';
|
||||
import get_payment_balance_for_user from './api/payments/get_payment_balance_for_user.js';
|
||||
import list_payment_methods_for_user from './api/payments/list_payment_methods_for_user.js';
|
||||
import list_invoices_for_user from './api/payments/list_invoices_for_user.js';
|
||||
import delete_payment_method_for_user from './api/payments/delete_payment_method_for_user.js';
|
||||
export const payments = {
|
||||
delete_payment_information_for_user,
|
||||
get_payment_information_for_user,
|
||||
create_payment_information_for_user,
|
||||
update_payment_information_for_user,
|
||||
create_payment_intent_for_user,
|
||||
get_payment_balance_for_user,
|
||||
list_payment_methods_for_user,
|
||||
list_invoices_for_user,
|
||||
delete_payment_method_for_user,
|
||||
};
|
||||
|
||||
import get_session_for_user from './api/sessions/get_session_for_user.js';
|
||||
export const sessions = { get_session_for_user };
|
1739
src/models.ts
Normal file
1739
src/models.ts
Normal file
File diff suppressed because it is too large
Load Diff
175
src/modelsGen.ts
Normal file
175
src/modelsGen.ts
Normal file
@ -0,0 +1,175 @@
|
||||
import fsp from 'node:fs/promises';
|
||||
import { OpenAPIV3 } from 'openapi-types';
|
||||
import apiGen from './apiGen.js';
|
||||
|
||||
main();
|
||||
|
||||
async function main() {
|
||||
const spec: OpenAPIV3.Document = JSON.parse(
|
||||
await fsp.readFile('./spec.json', 'utf8'),
|
||||
);
|
||||
const schemas = spec.components.schemas as {
|
||||
[key: string]: OpenAPIV3.SchemaObject;
|
||||
};
|
||||
const typeReference: { [key: string]: string } = {};
|
||||
const typeNameReference: { [key: string]: string } = {};
|
||||
let template = '';
|
||||
|
||||
const addTypeName = ($ref: string, name: string) => {
|
||||
typeNameReference[$ref] = name;
|
||||
};
|
||||
|
||||
const makeTypeStringForNode = (
|
||||
schema: OpenAPIV3.SchemaObject,
|
||||
name = '',
|
||||
isRoot = false,
|
||||
): string => {
|
||||
const separator = schema.nullable ? '?:' : ':';
|
||||
const namePart = name ? `${name}${separator}` : '';
|
||||
if (schema.type === 'string' && schema.enum) {
|
||||
return [
|
||||
addCommentInfo(
|
||||
schema,
|
||||
`${namePart} ${schema.enum.map((e) => `'${e}'`).join(' | ')}`,
|
||||
),
|
||||
'/* use-type */',
|
||||
].join('\n');
|
||||
}
|
||||
if (schema.type === 'string' || schema.type === 'boolean') {
|
||||
return addCommentInfo(
|
||||
schema,
|
||||
`${namePart} ${schema.type} ${
|
||||
!namePart && isRoot ? '/* use-type */' : ''
|
||||
}`,
|
||||
);
|
||||
}
|
||||
if (schema.type === 'number' || schema.type === 'integer') {
|
||||
return addCommentInfo(schema, `${namePart} number`);
|
||||
}
|
||||
if (schema.type === 'object') {
|
||||
const objectInner = Object.entries(schema.properties)
|
||||
.map(([key, subSchema]: [string, OpenAPIV3.SchemaObject]) => {
|
||||
if (!(subSchema.type === 'array') && !(subSchema.type === 'object')) {
|
||||
if (subSchema.allOf) {
|
||||
const ref = (subSchema.allOf[0] as any).$ref;
|
||||
return addCommentInfo(
|
||||
subSchema,
|
||||
`${key}: ${typeNameReference[ref]}`,
|
||||
);
|
||||
}
|
||||
return makeTypeStringForNode(subSchema, key);
|
||||
} else if (subSchema.type === 'array') {
|
||||
const items = subSchema.items;
|
||||
if ((items as any).$ref) {
|
||||
const ref = (items as any).$ref;
|
||||
return addCommentInfo(subSchema, `${key}: ${typeNameReference[ref]}[]`);
|
||||
}
|
||||
return `${makeTypeStringForNode(
|
||||
items as OpenAPIV3.SchemaObject,
|
||||
key,
|
||||
)}[]`;
|
||||
} else if (
|
||||
subSchema.type === 'object' &&
|
||||
subSchema.additionalProperties
|
||||
) {
|
||||
if ((subSchema.additionalProperties as any).$ref) {
|
||||
const ref = (subSchema.additionalProperties as any).$ref;
|
||||
return addCommentInfo(subSchema, `${key}: {[key: string] : ${typeNameReference[ref]}}`);
|
||||
}
|
||||
return `${key}: {[key: string] : ${makeTypeStringForNode(
|
||||
subSchema.additionalProperties as any,
|
||||
)}}`;
|
||||
}
|
||||
console.log(subSchema, key);
|
||||
throw 'subSchema not implemented ' + subSchema.type;
|
||||
})
|
||||
.join('; ');
|
||||
return `{${objectInner}}`;
|
||||
}
|
||||
if (
|
||||
JSON.stringify(Object.keys(schema)) === '["description"]' ||
|
||||
JSON.stringify(Object.keys(schema)) === '["description","nullable"]'
|
||||
) {
|
||||
return `${namePart} string`;
|
||||
}
|
||||
if (schema.oneOf) {
|
||||
const unionParts = schema.oneOf.map(
|
||||
(subSchema: OpenAPIV3.SchemaObject) => {
|
||||
if (!(subSchema.type === 'array') && !(subSchema.type === 'object')) {
|
||||
if (subSchema.allOf) {
|
||||
const ref = (subSchema.allOf[0] as any).$ref;
|
||||
return typeReference[ref];
|
||||
}
|
||||
return makeTypeStringForNode(subSchema);
|
||||
} else if (subSchema.type === 'array') {
|
||||
const items = subSchema.items;
|
||||
if ((items as any).$ref) {
|
||||
const ref = (items as any).$ref;
|
||||
return `${typeReference[ref]}[]`;
|
||||
}
|
||||
} else if (subSchema.type === 'object') {
|
||||
return makeTypeStringForNode(subSchema);
|
||||
}
|
||||
throw 'oneOf subSchema not implemented ' + subSchema.type;
|
||||
},
|
||||
);
|
||||
return `${namePart} ${unionParts.join(' | ')} /* use-type */`;
|
||||
}
|
||||
if (schema.type === 'array') {
|
||||
return `${name}: ${makeTypeStringForNode(schema.items as any)}[]`;
|
||||
}
|
||||
console.log(schema);
|
||||
throw 'not implemented';
|
||||
};
|
||||
|
||||
const componentRef = (key: string): string => '#/components/schemas/' + key;
|
||||
for (const key of Object.keys(schemas)) {
|
||||
addTypeName(componentRef(key), key + '_type');
|
||||
}
|
||||
for (const [key, schema] of Object.entries(schemas)) {
|
||||
const typeBody = makeTypeStringForNode(schema, '', true);
|
||||
const typeName = typeNameReference[componentRef(key)];
|
||||
typeReference[componentRef(key)] = typeBody;
|
||||
if (typeBody.includes('/* use-type */')) {
|
||||
template += `export type ${typeName} = ${typeBody.replaceAll(
|
||||
'/* use-type */',
|
||||
'',
|
||||
)}\n\n`;
|
||||
} else {
|
||||
template += `export interface ${typeName} ${typeBody}\n\n`;
|
||||
}
|
||||
}
|
||||
// console.log(typeReference);
|
||||
// console.log(typeNameReference);
|
||||
await fsp.writeFile(`./src/models.ts`, template, 'utf8');
|
||||
apiGen(typeNameReference)
|
||||
}
|
||||
|
||||
function addCommentInfo(schema: any, typeString: string) {
|
||||
const { enum: _enum, type, allOf, items, properties, additionalProperties, description, ...newSchema } = schema;
|
||||
if (!Object.keys(newSchema).length && !description) {
|
||||
return typeString;
|
||||
} else if (!Object.keys(newSchema).length && description) {
|
||||
if (
|
||||
typeString.includes('\n') ||
|
||||
typeString.includes('|') ||
|
||||
description.includes('\n')
|
||||
) {
|
||||
return `\n/* ${description} */\n${typeString}`;
|
||||
}
|
||||
return `${typeString} /* ${description} */`;
|
||||
} else if (Object.keys(newSchema).length <= 2 && description?.length < 50) {
|
||||
return `\n/* ${JSON.stringify({
|
||||
...newSchema,
|
||||
description,
|
||||
})
|
||||
.slice(1, -1)
|
||||
.replaceAll(',"', ', "')
|
||||
.replaceAll('"', '')} */\n${typeString}`;
|
||||
}
|
||||
return `\n/*${JSON.stringify(
|
||||
{ ...newSchema, description },
|
||||
null,
|
||||
2,
|
||||
)}*/\n${typeString}`;
|
||||
}
|
29
src/template.ts.txt
Normal file
29
src/template.ts.txt
Normal file
@ -0,0 +1,29 @@
|
||||
import fetch from 'node-fetch';
|
||||
import * as types from './src/models.ts';
|
||||
|
||||
interface FunctionNameParams {
|
||||
exampleParam: string;
|
||||
}
|
||||
|
||||
interface FunctionNameReturn {
|
||||
exampleReturn: string;
|
||||
}
|
||||
|
||||
export default async function functionName(
|
||||
functionNameParams: FunctionNameParams,
|
||||
): Promise<FunctionNameReturn> {
|
||||
const url = 'string' + functionNameParams.exampleParam;
|
||||
const fullUrl = 'https://api.kittycad.io' + url;
|
||||
const kittycadToken = process.env.KITTYCAD_TOKEN || ''
|
||||
const headers = {
|
||||
Authorization: `Bearer ${kittycadToken}`,
|
||||
};
|
||||
const fetchOptions = {
|
||||
method: 'METHOD',
|
||||
headers,
|
||||
body: 'BODY',
|
||||
};
|
||||
const response = await fetch(fullUrl, fetchOptions);
|
||||
const result = (await response.json()) as FunctionNameReturn;
|
||||
return result;
|
||||
}
|
26
tsconfig.json
Normal file
26
tsconfig.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"esModuleInterop": true,
|
||||
"target": "ES2022",
|
||||
"module": "ESNext",
|
||||
"lib": ["ES2022"],
|
||||
"rootDir": ".",
|
||||
"outDir": "build",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"importHelpers": true,
|
||||
"alwaysStrict": true,
|
||||
"sourceMap": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noImplicitReturns": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noImplicitAny": false,
|
||||
"noImplicitThis": false,
|
||||
"strictNullChecks": false,
|
||||
"declaration": true,
|
||||
"declarationDir": "./build/types",
|
||||
"declarationMap": true
|
||||
},
|
||||
"include": ["src/**/*", "__tests__/**/*"],
|
||||
}
|
Reference in New Issue
Block a user