@hautechai/sdk 0.0.1

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.
Files changed (51) hide show
  1. package/.env.example +5 -0
  2. package/.github/workflows/main.yml +43 -0
  3. package/LICENSE +19 -0
  4. package/README.md +62 -0
  5. package/dist/autogenerated/api.d.ts +3347 -0
  6. package/dist/autogenerated/api.js +4118 -0
  7. package/dist/autogenerated/base.d.ts +66 -0
  8. package/dist/autogenerated/base.js +59 -0
  9. package/dist/autogenerated/common.d.ts +65 -0
  10. package/dist/autogenerated/common.js +133 -0
  11. package/dist/autogenerated/configuration.d.ts +91 -0
  12. package/dist/autogenerated/configuration.js +39 -0
  13. package/dist/autogenerated/index.d.ts +13 -0
  14. package/dist/autogenerated/index.js +15 -0
  15. package/dist/index.d.ts +3 -0
  16. package/dist/index.js +3 -0
  17. package/dist/sdk/accounts/index.d.ts +13 -0
  18. package/dist/sdk/accounts/index.js +17 -0
  19. package/dist/sdk/api.d.ts +23 -0
  20. package/dist/sdk/api.js +48 -0
  21. package/dist/sdk/balances/index.d.ts +12 -0
  22. package/dist/sdk/balances/index.js +19 -0
  23. package/dist/sdk/collections/index.d.ts +28 -0
  24. package/dist/sdk/collections/index.js +31 -0
  25. package/dist/sdk/groups/index.d.ts +24 -0
  26. package/dist/sdk/groups/index.js +31 -0
  27. package/dist/sdk/images/index.d.ts +16 -0
  28. package/dist/sdk/images/index.js +36 -0
  29. package/dist/sdk/index.d.ts +167 -0
  30. package/dist/sdk/index.js +35 -0
  31. package/dist/sdk/operations/index.d.ts +42 -0
  32. package/dist/sdk/operations/index.js +64 -0
  33. package/dist/sdk/operations/updater.d.ts +11 -0
  34. package/dist/sdk/operations/updater.js +23 -0
  35. package/dist/sdk/stacks/index.d.ts +25 -0
  36. package/dist/sdk/stacks/index.js +30 -0
  37. package/dist/sdk/storage/index.d.ts +18 -0
  38. package/dist/sdk/storage/index.js +27 -0
  39. package/dist/sdk/utils/index.d.ts +5 -0
  40. package/dist/sdk/utils/index.js +6 -0
  41. package/dist/token/index.d.ts +15 -0
  42. package/dist/token/index.js +38 -0
  43. package/dist/token/permissions.d.ts +3 -0
  44. package/dist/token/permissions.js +40 -0
  45. package/dist/types.d.ts +54 -0
  46. package/dist/types.js +4 -0
  47. package/jest.setup.js +5 -0
  48. package/openapitools.json +7 -0
  49. package/package.json +37 -0
  50. package/scripts/generate.sh +3 -0
  51. package/tsconfig.json +14 -0
@@ -0,0 +1,31 @@
1
+ import { CollectionsApi } from '../../autogenerated';
2
+ import { useAutogeneratedAPI } from '../api';
3
+ const collections = (options) => {
4
+ const api = useAutogeneratedAPI({ API: CollectionsApi, options });
5
+ return {
6
+ create: async (props = {}) => api.call({
7
+ run: (methods) => methods.collectionsControllerCreateCollectionV1({ metadata: props.metadata }),
8
+ }),
9
+ get: async (props) => api.callWithReturningUndefinedOn404({
10
+ run: (methods) => methods.collectionsControllerGetCollectionV1(props.id),
11
+ }),
12
+ items: {
13
+ add: async (props) => api.call({
14
+ run: (methods) => methods.collectionsControllerAddItemsV1(props.collectionId, { itemIds: props.itemIds }),
15
+ }),
16
+ list: async (props) => api.call({
17
+ run: (methods) => methods.collectionsControllerListItemsV1(props.collectionId, props.cursor, props.orderBy, props.limit),
18
+ }),
19
+ remove: async (props) => api.call({
20
+ run: (methods) => methods.collectionsControllerRemoveItemsV1(props.collectionId, { itemIds: props.itemIds }),
21
+ }),
22
+ },
23
+ list: async (props = {}) => api.call({
24
+ run: (methods) => methods.collectionsControllerListCollectionsV1(props.orderBy, props.limit, props.cursor),
25
+ }),
26
+ updateMetadata: async (props) => api.call({
27
+ run: (methods) => methods.collectionsControllerUpdateMetadataV1(props.id, { overwrite: props.metadata }),
28
+ }),
29
+ };
30
+ };
31
+ export default collections;
@@ -0,0 +1,24 @@
1
+ import { SDKOptions } from '../../types';
2
+ import { AddAccountToGroupControllerParamsDtoRoleEnum, RemoveAccountFromGroupControllerParamsDtoRoleEnum } from '../../autogenerated';
3
+ declare const groups: (options: SDKOptions) => {
4
+ accounts: {
5
+ add: (props: {
6
+ accountId: string;
7
+ groupId: string;
8
+ role: AddAccountToGroupControllerParamsDtoRoleEnum;
9
+ }) => Promise<void>;
10
+ remove: (props: {
11
+ accountId: string;
12
+ groupId: string;
13
+ role: RemoveAccountFromGroupControllerParamsDtoRoleEnum;
14
+ }) => Promise<void>;
15
+ };
16
+ create: () => Promise<import("../../autogenerated").GroupEntity>;
17
+ delete: (props: {
18
+ id: string;
19
+ }) => Promise<void>;
20
+ get: (props: {
21
+ id: string;
22
+ }) => Promise<import("../../autogenerated").GroupEntity | undefined>;
23
+ };
24
+ export default groups;
@@ -0,0 +1,31 @@
1
+ import { GroupsApi, } from '../../autogenerated';
2
+ import { useAutogeneratedAPI } from '../api';
3
+ const groups = (options) => {
4
+ const api = useAutogeneratedAPI({ API: GroupsApi, options });
5
+ return {
6
+ accounts: {
7
+ add: async (props) => api.call({
8
+ run: (methods) => methods.groupsControllerAddAccountV1(props.groupId, {
9
+ accountId: props.accountId,
10
+ role: props.role,
11
+ }),
12
+ }),
13
+ remove: async (props) => api.call({
14
+ run: (methods) => methods.groupsControllerRemoveAccountV1(props.groupId, {
15
+ accountId: props.accountId,
16
+ role: props.role,
17
+ }),
18
+ }),
19
+ },
20
+ create: async () => api.call({
21
+ run: (methods) => methods.groupsControllerCreateGroupV1(),
22
+ }),
23
+ delete: async (props) => api.call({
24
+ run: (methods) => methods.groupsControllerDeleteGroupV1(props.id),
25
+ }),
26
+ get: (props) => api.callWithReturningUndefinedOn404({
27
+ run: (methods) => methods.groupsControllerGetGroupV1(props.id),
28
+ }),
29
+ };
30
+ };
31
+ export default groups;
@@ -0,0 +1,16 @@
1
+ import { SDKOptions } from '../../types';
2
+ declare const images: (options: SDKOptions) => {
3
+ createFromFile: (props: {
4
+ file: any;
5
+ }) => Promise<import("../../autogenerated").ImageEntity>;
6
+ createFromUrl: (props: {
7
+ url: string;
8
+ }) => Promise<import("../../autogenerated").ImageEntity>;
9
+ get: (props: {
10
+ id: string;
11
+ }) => Promise<import("../../autogenerated").ImageEntity | undefined>;
12
+ getUrls: (props: {
13
+ ids: string[];
14
+ }) => Promise<Record<string, string>>;
15
+ };
16
+ export default images;
@@ -0,0 +1,36 @@
1
+ import axios from 'axios';
2
+ import { ImagesApi } from '../../autogenerated';
3
+ import { useAutogeneratedAPI } from '../api';
4
+ const images = (options) => {
5
+ const api = useAutogeneratedAPI({ API: ImagesApi, options });
6
+ const createFromFile = async (props) => {
7
+ const uploadUrl = await api.call({
8
+ run: (methods) => methods.imagesControllerStartUploadV1(props.file),
9
+ transform: (data) => data.uploadUrl,
10
+ });
11
+ const formData = new FormData();
12
+ formData.append('file', props.file);
13
+ const response = await axios.put(uploadUrl, formData, {
14
+ headers: { 'Content-Type': 'multipart/form-data' },
15
+ });
16
+ const fileToken = response.data.fileToken;
17
+ const image = await api.call({ run: (methods) => methods.imagesControllerFinalizeUploadV1({ fileToken }) });
18
+ return image;
19
+ };
20
+ return {
21
+ createFromFile,
22
+ createFromUrl: async (props) => {
23
+ const response = await axios.get(props.url, { responseType: 'arraybuffer' });
24
+ const file = new Blob([response.data], { type: response.headers['content-type'] });
25
+ return createFromFile({ file });
26
+ },
27
+ get: async (props) => api.callWithReturningUndefinedOn404({
28
+ run: (methods) => methods.imagesControllerGetImageV1(props.id),
29
+ }),
30
+ getUrls: async (props) => api.call({
31
+ run: (methods) => methods.imagesControllerGetUrlsV1({ ids: props.ids }),
32
+ transform: (data) => data.reduce((acc, { id, url }) => ({ ...acc, [id]: url }), {}),
33
+ }),
34
+ };
35
+ };
36
+ export default images;
@@ -0,0 +1,167 @@
1
+ import { SDKOptions } from '../types';
2
+ export declare const createSDK: (options: SDKOptions) => {
3
+ accounts: {
4
+ create: (props?: {
5
+ alias?: string;
6
+ }) => Promise<import("../autogenerated").AccountEntity>;
7
+ get: (props: {
8
+ id: string;
9
+ }) => Promise<import("../autogenerated").AccountEntity | undefined>;
10
+ getByAlias: (props: {
11
+ alias: string;
12
+ }) => Promise<import("../autogenerated").AccountEntity | undefined>;
13
+ };
14
+ balances: {
15
+ add: (props: {
16
+ accountId: string;
17
+ amount: string;
18
+ }) => Promise<void>;
19
+ get: () => Promise<string>;
20
+ getByAccountId: (props: {
21
+ accountId: string;
22
+ }) => Promise<string>;
23
+ };
24
+ collections: {
25
+ create: (props?: {
26
+ metadata?: any;
27
+ }) => Promise<import("../autogenerated").CollectionEntity>;
28
+ get: (props: {
29
+ id: string;
30
+ }) => Promise<import("../autogenerated").CollectionEntity | undefined>;
31
+ items: {
32
+ add: (props: {
33
+ collectionId: string;
34
+ itemIds: string[];
35
+ }) => Promise<void>;
36
+ list: (props: {
37
+ collectionId: string;
38
+ } & import("../types").ListProps) => Promise<import("../autogenerated").ListCollectionItemsDto>;
39
+ remove: (props: {
40
+ collectionId: string;
41
+ itemIds: string[];
42
+ }) => Promise<void>;
43
+ };
44
+ list: (props?: import("../types").ListProps) => Promise<import("../autogenerated").ListCollectionsDto>;
45
+ updateMetadata: (props: {
46
+ id: string;
47
+ metadata?: any;
48
+ }) => Promise<import("../autogenerated").ResourceEntity>;
49
+ };
50
+ groups: {
51
+ accounts: {
52
+ add: (props: {
53
+ accountId: string;
54
+ groupId: string;
55
+ role: import("../autogenerated").AddAccountToGroupControllerParamsDtoRoleEnum;
56
+ }) => Promise<void>;
57
+ remove: (props: {
58
+ accountId: string;
59
+ groupId: string;
60
+ role: import("../autogenerated").RemoveAccountFromGroupControllerParamsDtoRoleEnum;
61
+ }) => Promise<void>;
62
+ };
63
+ create: () => Promise<import("../autogenerated").GroupEntity>;
64
+ delete: (props: {
65
+ id: string;
66
+ }) => Promise<void>;
67
+ get: (props: {
68
+ id: string;
69
+ }) => Promise<import("../autogenerated").GroupEntity | undefined>;
70
+ };
71
+ images: {
72
+ createFromFile: (props: {
73
+ file: any;
74
+ }) => Promise<import("../autogenerated").ImageEntity>;
75
+ createFromUrl: (props: {
76
+ url: string;
77
+ }) => Promise<import("../autogenerated").ImageEntity>;
78
+ get: (props: {
79
+ id: string;
80
+ }) => Promise<import("../autogenerated").ImageEntity | undefined>;
81
+ getUrls: (props: {
82
+ ids: string[];
83
+ }) => Promise<Record<string, string>>;
84
+ };
85
+ operations: {
86
+ create: {
87
+ generate: {
88
+ v1: (props: {
89
+ input: import("../autogenerated").GenerateV3Input;
90
+ metadata?: any;
91
+ }) => Promise<import("../autogenerated").OperationEntity>;
92
+ };
93
+ inpaint: {
94
+ v1: (props: {
95
+ input: import("../autogenerated").InpaintV1Input;
96
+ metadata?: any;
97
+ }) => Promise<import("../autogenerated").OperationEntity>;
98
+ };
99
+ };
100
+ get: (props: {
101
+ id: string;
102
+ }) => Promise<import("../autogenerated").OperationEntity | undefined>;
103
+ getMany: (props: {
104
+ ids: string[];
105
+ }) => Promise<import("../autogenerated").OperationEntity[]>;
106
+ list: (props?: import("../types").ListProps) => Promise<import("../autogenerated").ListOperationsDto>;
107
+ updateMetadata: (props: {
108
+ id: string;
109
+ metadata?: any;
110
+ }) => Promise<import("../autogenerated").ResourceEntity>;
111
+ updates: {
112
+ subscribe: (props: {
113
+ callback: (operation: import("../autogenerated").OperationEntity) => void;
114
+ }) => void;
115
+ unsubscribe: (props: {
116
+ callback: (operation: import("../autogenerated").OperationEntity) => void;
117
+ }) => void;
118
+ };
119
+ wait: (props: {
120
+ id: string;
121
+ timeoutInSeconds?: number;
122
+ }) => Promise<unknown>;
123
+ };
124
+ stacks: {
125
+ create: (props?: {
126
+ metadata?: any;
127
+ }) => Promise<import("../autogenerated").StackEntity>;
128
+ get: (props: {
129
+ id: string;
130
+ }) => Promise<import("../autogenerated").StackEntity | undefined>;
131
+ list: (props?: import("../types").ListProps) => Promise<import("../autogenerated").ListStacksDto>;
132
+ operations: {
133
+ add: (props: {
134
+ operationIds: string[];
135
+ stackId: string;
136
+ }) => Promise<void>;
137
+ remove: (props: {
138
+ operationIds: string[];
139
+ stackId: string;
140
+ }) => Promise<import("../autogenerated").StackEntity>;
141
+ };
142
+ updateMetadata: (props: {
143
+ id: string;
144
+ metadata?: any;
145
+ }) => Promise<import("../autogenerated").ResourceEntity>;
146
+ };
147
+ storage: {
148
+ create: (props: {
149
+ key: string;
150
+ value: any;
151
+ }) => Promise<any>;
152
+ delete: (props: {
153
+ key: string;
154
+ }) => Promise<void>;
155
+ getMany: (props: {
156
+ keys: string[];
157
+ }) => Promise<Record<string, any>>;
158
+ update: (props: {
159
+ key: string;
160
+ value: any;
161
+ }) => Promise<any>;
162
+ };
163
+ utils: {
164
+ seed: () => number;
165
+ };
166
+ };
167
+ export type SDK = ReturnType<typeof createSDK>;
@@ -0,0 +1,35 @@
1
+ import accounts from './accounts';
2
+ import balances from './balances';
3
+ import collections from './collections';
4
+ import groups from './groups';
5
+ import images from './images';
6
+ import jwt from 'jsonwebtoken';
7
+ import operations from './operations';
8
+ import stacks from './stacks';
9
+ import storage from './storage';
10
+ import utils from './utils';
11
+ export const createSDK = (options) => {
12
+ let token = undefined;
13
+ const authToken = async () => {
14
+ if (token) {
15
+ const decoded = jwt.decode(token);
16
+ const currentTime = Math.floor(Date.now() / 1000);
17
+ if (decoded.exp && decoded.exp > currentTime)
18
+ return token;
19
+ }
20
+ token = await options.authToken();
21
+ return token;
22
+ };
23
+ const optionsWithTokenRefresher = { ...options, authToken };
24
+ return {
25
+ accounts: accounts(optionsWithTokenRefresher),
26
+ balances: balances(optionsWithTokenRefresher),
27
+ collections: collections(optionsWithTokenRefresher),
28
+ groups: groups(optionsWithTokenRefresher),
29
+ images: images(optionsWithTokenRefresher),
30
+ operations: operations(optionsWithTokenRefresher),
31
+ stacks: stacks(optionsWithTokenRefresher),
32
+ storage: storage(optionsWithTokenRefresher),
33
+ utils: utils(optionsWithTokenRefresher),
34
+ };
35
+ };
@@ -0,0 +1,42 @@
1
+ import { SDKOptions, ListProps } from '../../types';
2
+ import { GenerateV3Input, InpaintV1Input } from '../../autogenerated';
3
+ declare const operations: (options: SDKOptions) => {
4
+ create: {
5
+ generate: {
6
+ v1: (props: {
7
+ input: GenerateV3Input;
8
+ metadata?: any;
9
+ }) => Promise<import("../../autogenerated").OperationEntity>;
10
+ };
11
+ inpaint: {
12
+ v1: (props: {
13
+ input: InpaintV1Input;
14
+ metadata?: any;
15
+ }) => Promise<import("../../autogenerated").OperationEntity>;
16
+ };
17
+ };
18
+ get: (props: {
19
+ id: string;
20
+ }) => Promise<import("../../autogenerated").OperationEntity | undefined>;
21
+ getMany: (props: {
22
+ ids: string[];
23
+ }) => Promise<import("../../autogenerated").OperationEntity[]>;
24
+ list: (props?: ListProps) => Promise<import("../../autogenerated").ListOperationsDto>;
25
+ updateMetadata: (props: {
26
+ id: string;
27
+ metadata?: any;
28
+ }) => Promise<import("../../autogenerated").ResourceEntity>;
29
+ updates: {
30
+ subscribe: (props: {
31
+ callback: (operation: import("../../autogenerated").OperationEntity) => void;
32
+ }) => void;
33
+ unsubscribe: (props: {
34
+ callback: (operation: import("../../autogenerated").OperationEntity) => void;
35
+ }) => void;
36
+ };
37
+ wait: (props: {
38
+ id: string;
39
+ timeoutInSeconds?: number;
40
+ }) => Promise<unknown>;
41
+ };
42
+ export default operations;
@@ -0,0 +1,64 @@
1
+ import createOperationUpdater from './updater';
2
+ import { OperationsApi } from '../../autogenerated';
3
+ import { useAutogeneratedAPI } from '../api';
4
+ const operations = (options) => {
5
+ const api = useAutogeneratedAPI({ API: OperationsApi, options });
6
+ const updates = createOperationUpdater(options);
7
+ return {
8
+ create: {
9
+ generate: {
10
+ v1: (props) => api.call({
11
+ run: (methods) => methods.operationsControllerRunGenerateV3V1({
12
+ input: props.input,
13
+ metadata: props.metadata,
14
+ }),
15
+ }),
16
+ },
17
+ inpaint: {
18
+ v1: (props) => api.call({
19
+ run: (methods) => methods.operationsControllerRunInpaintV1V1({
20
+ input: props.input,
21
+ metadata: props.metadata,
22
+ }),
23
+ }),
24
+ },
25
+ },
26
+ get: (props) => api.callWithReturningUndefinedOn404({
27
+ run: (methods) => methods.operationsControllerGetOperationV1(props.id),
28
+ }),
29
+ getMany: (props) => api.call({
30
+ run: (methods) => methods.operationsControllerGetOperationsV1({ ids: props.ids }),
31
+ }),
32
+ list: (props = {}) => api.call({
33
+ run: (methods) => methods.operationsControllerListOperationsV1(props.orderBy, props.limit, props.cursor),
34
+ }),
35
+ updateMetadata: async (props) => api.call({
36
+ run: (methods) => methods.operationsControllerUpdateMetadataV1(props.id, { overwrite: props.metadata }),
37
+ }),
38
+ updates,
39
+ wait: async (props) => new Promise((resolve, reject) => {
40
+ const initialDelay = 5000;
41
+ const delay = 2000;
42
+ const listenToOperation = (operation) => {
43
+ if (operation.id === props.id) {
44
+ clearTimeout(timeoutId);
45
+ resolve(operation);
46
+ updates.unsubscribe({ callback: listenToOperation });
47
+ }
48
+ };
49
+ updates.subscribe({ callback: listenToOperation });
50
+ let timeoutId;
51
+ const poll = async () => {
52
+ const operation = await api.call({
53
+ run: (methods) => methods.operationsControllerGetOperationV1(props.id),
54
+ });
55
+ if (operation.status !== 'pending')
56
+ return resolve(operation);
57
+ timeoutId = setTimeout(poll, delay);
58
+ updates.unsubscribe({ callback: listenToOperation });
59
+ };
60
+ timeoutId = setTimeout(poll, initialDelay);
61
+ }),
62
+ };
63
+ };
64
+ export default operations;
@@ -0,0 +1,11 @@
1
+ import { SDKOptions } from '../../types';
2
+ import { OperationEntity } from '../../autogenerated';
3
+ declare const createOperationUpdater: (options: SDKOptions) => {
4
+ subscribe: (props: {
5
+ callback: (operation: OperationEntity) => void;
6
+ }) => void;
7
+ unsubscribe: (props: {
8
+ callback: (operation: OperationEntity) => void;
9
+ }) => void;
10
+ };
11
+ export default createOperationUpdater;
@@ -0,0 +1,23 @@
1
+ import { createWebsocket } from '../api';
2
+ const createOperationUpdater = (options) => {
3
+ const eventListeners = [];
4
+ const eventListener = (operation) => {
5
+ eventListeners.forEach((listener) => listener(operation));
6
+ };
7
+ let websocketInited = false;
8
+ const initWebsocket = () => {
9
+ createWebsocket({ callback: eventListener, options, topic: 'operation' });
10
+ websocketInited = true;
11
+ };
12
+ return {
13
+ subscribe: (props) => {
14
+ eventListeners.push(props.callback);
15
+ if (!websocketInited)
16
+ initWebsocket();
17
+ },
18
+ unsubscribe: (props) => {
19
+ eventListeners.splice(eventListeners.indexOf(props.callback), 1);
20
+ },
21
+ };
22
+ };
23
+ export default createOperationUpdater;
@@ -0,0 +1,25 @@
1
+ import { SDKOptions, ListProps } from '../../types';
2
+ declare const stacks: (options: SDKOptions) => {
3
+ create: (props?: {
4
+ metadata?: any;
5
+ }) => Promise<import("../../autogenerated").StackEntity>;
6
+ get: (props: {
7
+ id: string;
8
+ }) => Promise<import("../../autogenerated").StackEntity | undefined>;
9
+ list: (props?: ListProps) => Promise<import("../../autogenerated").ListStacksDto>;
10
+ operations: {
11
+ add: (props: {
12
+ operationIds: string[];
13
+ stackId: string;
14
+ }) => Promise<void>;
15
+ remove: (props: {
16
+ operationIds: string[];
17
+ stackId: string;
18
+ }) => Promise<import("../../autogenerated").StackEntity>;
19
+ };
20
+ updateMetadata: (props: {
21
+ id: string;
22
+ metadata?: any;
23
+ }) => Promise<import("../../autogenerated").ResourceEntity>;
24
+ };
25
+ export default stacks;
@@ -0,0 +1,30 @@
1
+ import { StacksApi } from '../../autogenerated';
2
+ import { useAutogeneratedAPI } from '../api';
3
+ const stacks = (options) => {
4
+ const api = useAutogeneratedAPI({ API: StacksApi, options });
5
+ return {
6
+ create: async (props = {}) => api.call({
7
+ run: (methods) => methods.stacksControllerCreateStackV1({
8
+ metadata: props.metadata,
9
+ }),
10
+ }),
11
+ get: async (props) => api.callWithReturningUndefinedOn404({
12
+ run: (methods) => methods.stacksControllerGetStackV1(props.id),
13
+ }),
14
+ list: async (props = {}) => api.call({
15
+ run: (methods) => methods.stacksControllerListStacksV1(props.orderBy, props.limit, props.cursor),
16
+ }),
17
+ operations: {
18
+ add: async (props) => api.call({
19
+ run: (methods) => methods.stacksControllerAddOperationsV1(props.stackId, { operationIds: props.operationIds }),
20
+ }),
21
+ remove: async (props) => api.call({
22
+ run: (methods) => methods.stacksControllerRemoveOperationV1(props.stackId, { operationIds: props.operationIds }),
23
+ }),
24
+ },
25
+ updateMetadata: async (props) => api.call({
26
+ run: (methods) => methods.stacksControllerUpdateMetadataV1(props.id, { overwrite: props.metadata }),
27
+ }),
28
+ };
29
+ };
30
+ export default stacks;
@@ -0,0 +1,18 @@
1
+ import { SDKOptions } from '../../types';
2
+ declare const storage: (options: SDKOptions) => {
3
+ create: (props: {
4
+ key: string;
5
+ value: any;
6
+ }) => Promise<any>;
7
+ delete: (props: {
8
+ key: string;
9
+ }) => Promise<void>;
10
+ getMany: (props: {
11
+ keys: string[];
12
+ }) => Promise<Record<string, any>>;
13
+ update: (props: {
14
+ key: string;
15
+ value: any;
16
+ }) => Promise<any>;
17
+ };
18
+ export default storage;
@@ -0,0 +1,27 @@
1
+ import { StorageApi } from '../../autogenerated';
2
+ import { useAutogeneratedAPI } from '../api';
3
+ const storage = (options) => {
4
+ const api = useAutogeneratedAPI({ API: StorageApi, options });
5
+ return {
6
+ create: async (props) => api.call({
7
+ run: (methods) => methods.storageControllerCreateRecordV1({
8
+ key: props.key,
9
+ value: props.value,
10
+ }),
11
+ }),
12
+ delete: async (props) => api.call({
13
+ run: (methods) => methods.storageControllerDeleteRecordV1({ key: props.key }),
14
+ }),
15
+ getMany: async (props) => api.call({
16
+ run: (methods) => methods.storageControllerGetRecordsV1({ keys: props.keys }),
17
+ transform: (response) => response.reduce((acc, item) => {
18
+ acc[item.key] = item.value;
19
+ return acc;
20
+ }, {}),
21
+ }),
22
+ update: async (props) => api.call({
23
+ run: (methods) => methods.storageControllerUpdateRecordV1({ key: props.key, value: props.value }),
24
+ }),
25
+ };
26
+ };
27
+ export default storage;
@@ -0,0 +1,5 @@
1
+ import { SDKOptions } from '../../types';
2
+ declare const utils: (options: SDKOptions) => {
3
+ seed: () => number;
4
+ };
5
+ export default utils;
@@ -0,0 +1,6 @@
1
+ const utils = (options) => {
2
+ return {
3
+ seed: () => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER),
4
+ };
5
+ };
6
+ export default utils;
@@ -0,0 +1,15 @@
1
+ import { MethodsPermissions } from '../types';
2
+ export declare const createTokenSigner: (options: {
3
+ appId: string;
4
+ appKeyId: string;
5
+ appKeySecret: string;
6
+ }) => {
7
+ createAccountToken: (props: {
8
+ accountId: string;
9
+ expiresInSeconds: number;
10
+ permissions?: Partial<MethodsPermissions>;
11
+ }) => string;
12
+ createRootToken: (props: {
13
+ expiresInSeconds: number;
14
+ }) => string;
15
+ };
@@ -0,0 +1,38 @@
1
+ import { defaultPermissions, defaultRootPermissions } from './permissions';
2
+ import jwt from 'jsonwebtoken';
3
+ const createPrivateKey = (key) => {
4
+ const header = `-----BEGIN PRIVATE KEY-----\n`;
5
+ const footer = `\n-----END PRIVATE KEY-----`;
6
+ // @ts-ignore
7
+ const keyBody = key.match(/.{1,64}/g).join('\n');
8
+ return header + keyBody + footer;
9
+ };
10
+ const createToken = (props) => {
11
+ const privateKey = createPrivateKey(props.appKeySecret);
12
+ return jwt.sign(props.payload, privateKey, {
13
+ algorithm: 'RS256',
14
+ expiresIn: props.expiresInSeconds,
15
+ keyid: props.appKeyId,
16
+ });
17
+ };
18
+ export const createTokenSigner = (options) => ({
19
+ createAccountToken: (props) => createToken({
20
+ appKeyId: options.appKeyId,
21
+ appKeySecret: options.appKeySecret,
22
+ expiresInSeconds: props.expiresInSeconds,
23
+ payload: {
24
+ iss: options.appId,
25
+ permissions: { ...defaultPermissions, ...(props.permissions ?? {}) },
26
+ sub: props.accountId,
27
+ },
28
+ }),
29
+ createRootToken: (props) => createToken({
30
+ appKeyId: options.appKeyId,
31
+ appKeySecret: options.appKeySecret,
32
+ expiresInSeconds: props.expiresInSeconds ?? 3600,
33
+ payload: {
34
+ iss: options.appId,
35
+ permissions: defaultRootPermissions,
36
+ },
37
+ }),
38
+ });
@@ -0,0 +1,3 @@
1
+ import { MethodsPermissions } from '../types';
2
+ export declare const defaultPermissions: MethodsPermissions;
3
+ export declare const defaultRootPermissions: MethodsPermissions;