@hautechai/sdk 0.0.12 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,76 @@
1
+ export type MethodsPermissions = {
2
+ access: {
3
+ add: boolean;
4
+ read: boolean;
5
+ remove: boolean;
6
+ };
7
+ accounts: {
8
+ create: boolean;
9
+ read: boolean;
10
+ };
11
+ balances: {
12
+ read: boolean;
13
+ update: boolean;
14
+ self: {
15
+ read: boolean;
16
+ update: boolean;
17
+ };
18
+ };
19
+ collections: {
20
+ create: boolean;
21
+ read: boolean;
22
+ update: boolean;
23
+ items: {
24
+ add: boolean;
25
+ read: boolean;
26
+ remove: boolean;
27
+ };
28
+ };
29
+ groups: {
30
+ create: boolean;
31
+ read: boolean;
32
+ delete: boolean;
33
+ accounts: {
34
+ add: boolean;
35
+ remove: boolean;
36
+ read: boolean;
37
+ };
38
+ };
39
+ images: {
40
+ create: boolean;
41
+ read: boolean;
42
+ };
43
+ operations: {
44
+ create: boolean;
45
+ read: boolean;
46
+ metadata: {
47
+ update: boolean;
48
+ };
49
+ };
50
+ pipelines: {
51
+ create: boolean;
52
+ read: boolean;
53
+ update: boolean;
54
+ };
55
+ poses: {
56
+ create: boolean;
57
+ read: boolean;
58
+ };
59
+ stacks: {
60
+ create: boolean;
61
+ read: boolean;
62
+ items: {
63
+ add: boolean;
64
+ remove: boolean;
65
+ };
66
+ metadata: {
67
+ update: boolean;
68
+ };
69
+ };
70
+ storage: {
71
+ create: boolean;
72
+ delete: boolean;
73
+ read: boolean;
74
+ update: boolean;
75
+ };
76
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -162,6 +162,37 @@ export declare const createSDK: (options: SDKOptions) => {
162
162
  timeoutInSeconds?: number;
163
163
  }) => Promise<import("../types").OperationEntity>;
164
164
  };
165
+ pipelines: {
166
+ create: (props: {
167
+ metadata?: any;
168
+ tasks: (pipeline: ReturnType<() => import("@hautechai/pipelines").Pipeline<{
169
+ collections: {
170
+ create: (params: import("../autogenerated").CreateCollectionParamsDto) => Promise<import("../types").CollectionEntity>;
171
+ get: (params: import("../autogenerated").GetCollectionParamsDto) => Promise<import("../types").CollectionEntity>;
172
+ };
173
+ stacks: {
174
+ create: (params: import("../autogenerated").CreateStackParamsDto) => Promise<import("../types").StackEntity>;
175
+ get: (params: import("../autogenerated").ListStacksParamsDto) => Promise<import("../types").StackEntity>;
176
+ };
177
+ }>>) => ReturnType<() => import("@hautechai/pipelines").Pipeline<{
178
+ collections: {
179
+ create: (params: import("../autogenerated").CreateCollectionParamsDto) => Promise<import("../types").CollectionEntity>;
180
+ get: (params: import("../autogenerated").GetCollectionParamsDto) => Promise<import("../types").CollectionEntity>;
181
+ };
182
+ stacks: {
183
+ create: (params: import("../autogenerated").CreateStackParamsDto) => Promise<import("../types").StackEntity>;
184
+ get: (params: import("../autogenerated").ListStacksParamsDto) => Promise<import("../types").StackEntity>;
185
+ };
186
+ }>>;
187
+ }) => Promise<import("../types").PipelineEntity>;
188
+ get: (props: {
189
+ id: string;
190
+ }) => Promise<import("../types").PipelineEntity | undefined>;
191
+ wait: (props: {
192
+ id: string;
193
+ timeoutInSeconds?: number;
194
+ }) => Promise<import("../types").PipelineEntity>;
195
+ };
165
196
  stacks: {
166
197
  create: (props?: {
167
198
  metadata?: any;
package/dist/sdk/index.js CHANGED
@@ -5,6 +5,7 @@ import groups from './groups';
5
5
  import images from './images';
6
6
  import { jwtDecode } from 'jwt-decode';
7
7
  import operations from './operations';
8
+ import pipelines from './pipelines';
8
9
  import stacks from './stacks';
9
10
  import storage from './storage';
10
11
  import utils from './utils';
@@ -28,6 +29,7 @@ export const createSDK = (options) => {
28
29
  groups: groups(optionsWithTokenRefresher),
29
30
  images: images(optionsWithTokenRefresher),
30
31
  operations: operations(optionsWithTokenRefresher),
32
+ pipelines: pipelines(optionsWithTokenRefresher),
31
33
  stacks: stacks(optionsWithTokenRefresher),
32
34
  storage: storage(optionsWithTokenRefresher),
33
35
  utils: utils(optionsWithTokenRefresher),
@@ -0,0 +1,35 @@
1
+ import { CollectionEntity, CreateCollectionParamsDto, CreateStackParamsDto, GetCollectionParamsDto, ListStacksParamsDto, PipelineEntity, StackEntity } from '../../autogenerated';
2
+ import { SDKOptions } from '../../types';
3
+ import { Pipeline } from '@hautechai/pipelines';
4
+ declare const pipelines: (options: SDKOptions) => {
5
+ create: (props: {
6
+ metadata?: any;
7
+ tasks: (pipeline: ReturnType<() => Pipeline<{
8
+ collections: {
9
+ create: (params: CreateCollectionParamsDto) => Promise<CollectionEntity>;
10
+ get: (params: GetCollectionParamsDto) => Promise<CollectionEntity>;
11
+ };
12
+ stacks: {
13
+ create: (params: CreateStackParamsDto) => Promise<StackEntity>;
14
+ get: (params: ListStacksParamsDto) => Promise<StackEntity>;
15
+ };
16
+ }>>) => ReturnType<() => Pipeline<{
17
+ collections: {
18
+ create: (params: CreateCollectionParamsDto) => Promise<CollectionEntity>;
19
+ get: (params: GetCollectionParamsDto) => Promise<CollectionEntity>;
20
+ };
21
+ stacks: {
22
+ create: (params: CreateStackParamsDto) => Promise<StackEntity>;
23
+ get: (params: ListStacksParamsDto) => Promise<StackEntity>;
24
+ };
25
+ }>>;
26
+ }) => Promise<PipelineEntity>;
27
+ get: (props: {
28
+ id: string;
29
+ }) => Promise<PipelineEntity | undefined>;
30
+ wait: (props: {
31
+ id: string;
32
+ timeoutInSeconds?: number;
33
+ }) => Promise<PipelineEntity>;
34
+ };
35
+ export default pipelines;
@@ -0,0 +1,53 @@
1
+ import { CallApi, PipelinesApi, } from '../../autogenerated';
2
+ import { Pipeline } from '@hautechai/pipelines';
3
+ import { useAutogeneratedAPI } from '../api';
4
+ const pipelines = (options) => {
5
+ const api = useAutogeneratedAPI({ API: PipelinesApi, options });
6
+ const callAPI = useAutogeneratedAPI({ API: CallApi, options });
7
+ const createPipeline = () => new Pipeline({
8
+ collections: {
9
+ create: (params) => callAPI.call({
10
+ run: (methods) => methods.callControllerCallCollectionsCreateV1(params),
11
+ }),
12
+ get: (params) => callAPI.call({
13
+ run: (methods) => methods.callControllerCallCollectionsGetV1(params),
14
+ }),
15
+ },
16
+ stacks: {
17
+ create: (params) => callAPI.call({
18
+ run: (methods) => methods.callControllerCallStacksCreateV1(params),
19
+ }),
20
+ get: (params) => callAPI.call({
21
+ run: (methods) => methods.callControllerCallStacksListV1(params),
22
+ }),
23
+ },
24
+ });
25
+ return {
26
+ create: async (props) => api.call({
27
+ run: (methods) => methods.pipelinesControllerCreatePipelineV1({
28
+ metadata: props.metadata,
29
+ tasks: props.tasks(createPipeline()).tasks,
30
+ }),
31
+ }),
32
+ get: async (props) => api.callWithReturningUndefinedOn404({
33
+ run: (methods) => methods.pipelinesControllerGetPipelineV1(props.id),
34
+ }),
35
+ wait: async (props) => new Promise((resolve, reject) => {
36
+ const initialDelay = 5000;
37
+ const delay = 2000;
38
+ let timeoutId;
39
+ const poll = async () => {
40
+ const pipeline = (await api.call({
41
+ run: (methods) => methods.pipelinesControllerGetPipelineV1(props.id),
42
+ }));
43
+ if (pipeline.status === 'completed')
44
+ return resolve(pipeline);
45
+ if (pipeline.status === 'failed')
46
+ return reject(pipeline);
47
+ timeoutId = setTimeout(poll, delay);
48
+ };
49
+ timeoutId = setTimeout(poll, initialDelay);
50
+ }),
51
+ };
52
+ };
53
+ export default pipelines;
@@ -1,4 +1,4 @@
1
- import { MethodsPermissions } from '../types';
1
+ import { MethodsPermissions } from '../autogenerated/permissions';
2
2
  export declare const createTokenSigner: (options: {
3
3
  appId: string;
4
4
  appKeyId: string;
@@ -16,6 +16,21 @@ const createToken = (props) => {
16
16
  keyid: props.appKeyId,
17
17
  });
18
18
  };
19
+ const serializePermissions = (permissions) => {
20
+ const result = [];
21
+ const traverse = (obj, path = []) => {
22
+ for (const [key, value] of Object.entries(obj)) {
23
+ if (typeof value === 'boolean' && value === true) {
24
+ result.push(path.concat(key).join(':'));
25
+ }
26
+ else if (typeof value === 'object') {
27
+ traverse(value, path.concat(key));
28
+ }
29
+ }
30
+ };
31
+ traverse(permissions);
32
+ return result;
33
+ };
19
34
  export const createTokenSigner = (options) => ({
20
35
  createAccountToken: (props) => createToken({
21
36
  appKeyId: options.appKeyId,
@@ -23,7 +38,7 @@ export const createTokenSigner = (options) => ({
23
38
  expiresInSeconds: props.expiresInSeconds,
24
39
  payload: {
25
40
  iss: options.appId,
26
- permissions: { ...defaultPermissions, ...(props.permissions ?? {}) },
41
+ permissions: serializePermissions({ ...defaultPermissions, ...(props.permissions ?? {}) }),
27
42
  sub: props.accountId,
28
43
  },
29
44
  }),
@@ -33,7 +48,7 @@ export const createTokenSigner = (options) => ({
33
48
  expiresInSeconds: props.expiresInSeconds ?? 3600,
34
49
  payload: {
35
50
  iss: options.appId,
36
- permissions: defaultRootPermissions,
51
+ permissions: serializePermissions(defaultRootPermissions),
37
52
  },
38
53
  }),
39
54
  });
@@ -1,3 +1,3 @@
1
- import { MethodsPermissions } from '../types';
1
+ import { MethodsPermissions } from '../autogenerated/permissions';
2
2
  export declare const defaultPermissions: MethodsPermissions;
3
3
  export declare const defaultRootPermissions: MethodsPermissions;
package/dist/types.d.ts CHANGED
@@ -10,46 +10,4 @@ export type ListProps = {
10
10
  export declare class ListResponse<T> extends Array<T> {
11
11
  nextCursor?: string;
12
12
  }
13
- type Add = {
14
- add: boolean;
15
- };
16
- type Remove = {
17
- remove: boolean;
18
- };
19
- type Create = {
20
- create: boolean;
21
- };
22
- type Delete = {
23
- delete: boolean;
24
- };
25
- type Read = {
26
- read: boolean;
27
- };
28
- type Update = {
29
- update: boolean;
30
- };
31
- export interface MethodsPermissions {
32
- access: Add & Read & Remove;
33
- accounts: Create & Read;
34
- balances: Read & Update & {
35
- self: Read & Update;
36
- };
37
- collections: Create & Read & Update & {
38
- items: Add & Read & Remove;
39
- };
40
- groups: Create & Read & Delete & {
41
- accounts: Add & Remove & Read;
42
- };
43
- images: Create & Read;
44
- operations: Create & Read & {
45
- metadata: Update;
46
- };
47
- pipelines: Create & Read & Update;
48
- poses: Create & Read;
49
- stacks: Create & Read & {
50
- items: Add & Remove;
51
- metadata: Update;
52
- };
53
- storage: Create & Delete & Read & Update;
54
- }
55
13
  export { AccountEntity, CollectionEntity, GroupEntity, ImageEntity, OperationEntity, PipelineEntity, ResourceEntity, StackEntity, StorageEntity, } from './autogenerated/api';
package/dist/types.js CHANGED
@@ -1,3 +1,5 @@
1
1
  export class ListResponse extends Array {
2
2
  }
3
3
  // ------------------------------------------------------------
4
+ // AUTOGENERATED TYPES END
5
+ // ------------------------------------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hautechai/sdk",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "license": "MIT",
5
5
  "keywords": [],
6
6
  "repository": {
@@ -17,6 +17,7 @@
17
17
  },
18
18
  "description": "Hautech SDK",
19
19
  "dependencies": {
20
+ "@hautechai/pipelines": "0.1.0",
20
21
  "axios": "1.6.1",
21
22
  "jsonwebtoken": "8.5.1",
22
23
  "jwt-decode": "4.0.0",
@@ -0,0 +1,54 @@
1
+ #!/bin/node
2
+
3
+ const url = process.argv[2];
4
+ const outputFilePath = process.argv[3];
5
+
6
+ const loadPermissions = async () => {
7
+ const response = await fetch(url);
8
+ const data = await response.json();
9
+
10
+ const output = {};
11
+
12
+ // Process each permission string into nested structure
13
+ data.forEach((permission) => {
14
+ const parts = permission.split(':');
15
+ let current = output;
16
+
17
+ // Build nested objects for each part
18
+ for (let i = 0; i < parts.length - 1; i++) {
19
+ const part = parts[i];
20
+ if (!current[part]) {
21
+ current[part] = {};
22
+ }
23
+ current = current[part];
24
+ }
25
+
26
+ // Set the final property to boolean type
27
+ const lastPart = parts[parts.length - 1];
28
+ current[lastPart] = 'boolean';
29
+ });
30
+
31
+ // Convert to TypeScript interface string
32
+ const generateTypeString = (obj, indent = '') => {
33
+ const entries = Object.entries(obj);
34
+ if (entries.length === 0) return '{}';
35
+
36
+ return `{\n${entries
37
+ .map(([key, value]) => {
38
+ const valueStr = typeof value === 'string' ? value : generateTypeString(value, indent + ' ');
39
+ return `${indent} ${key}: ${valueStr};`;
40
+ })
41
+ .join('\n')}\n${indent}}`;
42
+ };
43
+
44
+ const typeString = generateTypeString(output);
45
+
46
+ const fs = require('fs');
47
+
48
+ const fileContent = `// This file is auto-generated. Do not edit manually.
49
+ export type MethodsPermissions = ${typeString};`;
50
+
51
+ fs.writeFileSync(outputFilePath, fileContent);
52
+ };
53
+
54
+ loadPermissions();
@@ -1,3 +1,6 @@
1
1
  #!/bin/bash
2
2
 
3
- ./node_modules/.bin/openapi-generator-cli generate -i https://api.dev.hautech.ai/swagger.json -g typescript-axios -o ./src/autogenerated
3
+ API_URL="https://api.dev.hautech.ai"
4
+
5
+ ./node_modules/.bin/openapi-generator-cli generate -i $API_URL/swagger.json -g typescript-axios -o ./src/autogenerated
6
+ node ./scripts/generate-permissions.js $API_URL/v1/permissions/available ./src/autogenerated/permissions.ts