@hautechai/sdk 0.0.14 → 0.0.16
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.
- package/dist/sdk/index.d.ts +30 -11
- package/dist/sdk/index.js +2 -2
- package/dist/sdk/pipelines/index.d.ts +30 -11
- package/dist/sdk/pipelines/index.js +2 -1
- package/dist/token/index.d.ts +2 -2
- package/dist/token/index.js +14 -13
- package/dist/token/permissions.d.ts +0 -1
- package/dist/token/permissions.js +0 -18
- package/package.json +2 -3
- package/jest.setup.js +0 -5
package/dist/sdk/index.d.ts
CHANGED
|
@@ -163,18 +163,37 @@ export declare const createSDK: (options: SDKOptions) => {
|
|
|
163
163
|
}) => Promise<import("../types").OperationEntity>;
|
|
164
164
|
};
|
|
165
165
|
pipelines: {
|
|
166
|
+
constructTemplate: (consructPipeline: (pipeline: import("@hautechai/pipelines").Pipeline<{
|
|
167
|
+
collections: {
|
|
168
|
+
create: (params: import("../autogenerated").CreateCollectionParamsDto) => Promise<import("../types").CollectionEntity>;
|
|
169
|
+
get: (params: import("../autogenerated").GetCollectionParamsDto) => Promise<import("../types").CollectionEntity>;
|
|
170
|
+
};
|
|
171
|
+
stacks: {
|
|
172
|
+
create: (params: import("../autogenerated").CreateStackParamsDto) => Promise<import("../types").StackEntity>;
|
|
173
|
+
get: (params: import("../autogenerated").ListStacksParamsDto) => Promise<import("../types").StackEntity>;
|
|
174
|
+
};
|
|
175
|
+
}>) => import("@hautechai/pipelines").Pipeline<{
|
|
176
|
+
collections: {
|
|
177
|
+
create: (params: import("../autogenerated").CreateCollectionParamsDto) => Promise<import("../types").CollectionEntity>;
|
|
178
|
+
get: (params: import("../autogenerated").GetCollectionParamsDto) => Promise<import("../types").CollectionEntity>;
|
|
179
|
+
};
|
|
180
|
+
stacks: {
|
|
181
|
+
create: (params: import("../autogenerated").CreateStackParamsDto) => Promise<import("../types").StackEntity>;
|
|
182
|
+
get: (params: import("../autogenerated").ListStacksParamsDto) => Promise<import("../types").StackEntity>;
|
|
183
|
+
};
|
|
184
|
+
}>) => import("@hautechai/pipelines").Pipeline<{
|
|
185
|
+
collections: {
|
|
186
|
+
create: (params: import("../autogenerated").CreateCollectionParamsDto) => Promise<import("../types").CollectionEntity>;
|
|
187
|
+
get: (params: import("../autogenerated").GetCollectionParamsDto) => Promise<import("../types").CollectionEntity>;
|
|
188
|
+
};
|
|
189
|
+
stacks: {
|
|
190
|
+
create: (params: import("../autogenerated").CreateStackParamsDto) => Promise<import("../types").StackEntity>;
|
|
191
|
+
get: (params: import("../autogenerated").ListStacksParamsDto) => Promise<import("../types").StackEntity>;
|
|
192
|
+
};
|
|
193
|
+
}>;
|
|
166
194
|
create: (props: {
|
|
167
195
|
metadata?: any;
|
|
168
|
-
|
|
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<{
|
|
196
|
+
template: import("@hautechai/pipelines").Pipeline<{
|
|
178
197
|
collections: {
|
|
179
198
|
create: (params: import("../autogenerated").CreateCollectionParamsDto) => Promise<import("../types").CollectionEntity>;
|
|
180
199
|
get: (params: import("../autogenerated").GetCollectionParamsDto) => Promise<import("../types").CollectionEntity>;
|
|
@@ -183,7 +202,7 @@ export declare const createSDK: (options: SDKOptions) => {
|
|
|
183
202
|
create: (params: import("../autogenerated").CreateStackParamsDto) => Promise<import("../types").StackEntity>;
|
|
184
203
|
get: (params: import("../autogenerated").ListStacksParamsDto) => Promise<import("../types").StackEntity>;
|
|
185
204
|
};
|
|
186
|
-
}
|
|
205
|
+
}>;
|
|
187
206
|
}) => Promise<import("../types").PipelineEntity>;
|
|
188
207
|
get: (props: {
|
|
189
208
|
id: string;
|
package/dist/sdk/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import balances from './balances';
|
|
|
3
3
|
import collections from './collections';
|
|
4
4
|
import groups from './groups';
|
|
5
5
|
import images from './images';
|
|
6
|
-
import {
|
|
6
|
+
import { decodeJwt } from 'jose';
|
|
7
7
|
import operations from './operations';
|
|
8
8
|
import pipelines from './pipelines';
|
|
9
9
|
import stacks from './stacks';
|
|
@@ -13,7 +13,7 @@ export const createSDK = (options) => {
|
|
|
13
13
|
let token = undefined;
|
|
14
14
|
const authToken = async () => {
|
|
15
15
|
if (token) {
|
|
16
|
-
const decoded =
|
|
16
|
+
const decoded = decodeJwt(token);
|
|
17
17
|
const currentTime = Math.floor(Date.now() / 1000);
|
|
18
18
|
if (decoded.exp && decoded.exp > currentTime)
|
|
19
19
|
return token;
|
|
@@ -2,9 +2,37 @@ import { CollectionEntity, CreateCollectionParamsDto, CreateStackParamsDto, GetC
|
|
|
2
2
|
import { SDKOptions } from '../../types';
|
|
3
3
|
import { Pipeline } from '@hautechai/pipelines';
|
|
4
4
|
declare const pipelines: (options: SDKOptions) => {
|
|
5
|
+
constructTemplate: (consructPipeline: (pipeline: Pipeline<{
|
|
6
|
+
collections: {
|
|
7
|
+
create: (params: CreateCollectionParamsDto) => Promise<CollectionEntity>;
|
|
8
|
+
get: (params: GetCollectionParamsDto) => Promise<CollectionEntity>;
|
|
9
|
+
};
|
|
10
|
+
stacks: {
|
|
11
|
+
create: (params: CreateStackParamsDto) => Promise<StackEntity>;
|
|
12
|
+
get: (params: ListStacksParamsDto) => Promise<StackEntity>;
|
|
13
|
+
};
|
|
14
|
+
}>) => Pipeline<{
|
|
15
|
+
collections: {
|
|
16
|
+
create: (params: CreateCollectionParamsDto) => Promise<CollectionEntity>;
|
|
17
|
+
get: (params: GetCollectionParamsDto) => Promise<CollectionEntity>;
|
|
18
|
+
};
|
|
19
|
+
stacks: {
|
|
20
|
+
create: (params: CreateStackParamsDto) => Promise<StackEntity>;
|
|
21
|
+
get: (params: ListStacksParamsDto) => Promise<StackEntity>;
|
|
22
|
+
};
|
|
23
|
+
}>) => Pipeline<{
|
|
24
|
+
collections: {
|
|
25
|
+
create: (params: CreateCollectionParamsDto) => Promise<CollectionEntity>;
|
|
26
|
+
get: (params: GetCollectionParamsDto) => Promise<CollectionEntity>;
|
|
27
|
+
};
|
|
28
|
+
stacks: {
|
|
29
|
+
create: (params: CreateStackParamsDto) => Promise<StackEntity>;
|
|
30
|
+
get: (params: ListStacksParamsDto) => Promise<StackEntity>;
|
|
31
|
+
};
|
|
32
|
+
}>;
|
|
5
33
|
create: (props: {
|
|
6
34
|
metadata?: any;
|
|
7
|
-
|
|
35
|
+
template: Pipeline<{
|
|
8
36
|
collections: {
|
|
9
37
|
create: (params: CreateCollectionParamsDto) => Promise<CollectionEntity>;
|
|
10
38
|
get: (params: GetCollectionParamsDto) => Promise<CollectionEntity>;
|
|
@@ -13,16 +41,7 @@ declare const pipelines: (options: SDKOptions) => {
|
|
|
13
41
|
create: (params: CreateStackParamsDto) => Promise<StackEntity>;
|
|
14
42
|
get: (params: ListStacksParamsDto) => Promise<StackEntity>;
|
|
15
43
|
};
|
|
16
|
-
}
|
|
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
|
-
}>>;
|
|
44
|
+
}>;
|
|
26
45
|
}) => Promise<PipelineEntity>;
|
|
27
46
|
get: (props: {
|
|
28
47
|
id: string;
|
|
@@ -23,10 +23,11 @@ const pipelines = (options) => {
|
|
|
23
23
|
},
|
|
24
24
|
});
|
|
25
25
|
return {
|
|
26
|
+
constructTemplate: (consructPipeline) => consructPipeline(createPipeline()),
|
|
26
27
|
create: async (props) => api.call({
|
|
27
28
|
run: (methods) => methods.pipelinesControllerCreatePipelineV1({
|
|
28
29
|
metadata: props.metadata,
|
|
29
|
-
tasks: props.
|
|
30
|
+
tasks: props.template.tasks,
|
|
30
31
|
}),
|
|
31
32
|
}),
|
|
32
33
|
get: async (props) => api.callWithReturningUndefinedOn404({
|
package/dist/token/index.d.ts
CHANGED
|
@@ -8,8 +8,8 @@ export declare const createTokenSigner: (options: {
|
|
|
8
8
|
accountId: string;
|
|
9
9
|
expiresInSeconds: number;
|
|
10
10
|
permissions?: Partial<MethodsPermissions>;
|
|
11
|
-
}) =>
|
|
11
|
+
}) => Promise<string>;
|
|
12
12
|
createRootToken: (props: {
|
|
13
13
|
expiresInSeconds: number;
|
|
14
|
-
}) =>
|
|
14
|
+
}) => Promise<string>;
|
|
15
15
|
};
|
package/dist/token/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { defaultPermissions
|
|
1
|
+
import { defaultPermissions } from './permissions';
|
|
2
|
+
import * as jose from 'jose';
|
|
2
3
|
const createPrivateKey = (key) => {
|
|
3
4
|
const header = `-----BEGIN PRIVATE KEY-----\n`;
|
|
4
5
|
const footer = `\n-----END PRIVATE KEY-----`;
|
|
@@ -6,15 +7,15 @@ const createPrivateKey = (key) => {
|
|
|
6
7
|
const keyBody = key.match(/.{1,64}/g).join('\n');
|
|
7
8
|
return header + keyBody + footer;
|
|
8
9
|
};
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const privateKey =
|
|
13
|
-
return
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
const createToken = async (props) => {
|
|
11
|
+
const alg = 'RS256';
|
|
12
|
+
const pkcs8 = createPrivateKey(props.appKeySecret);
|
|
13
|
+
const privateKey = await jose.importPKCS8(pkcs8, alg);
|
|
14
|
+
return await new jose.SignJWT(props.payload)
|
|
15
|
+
.setIssuedAt()
|
|
16
|
+
.setExpirationTime(`${props.expiresInSeconds}s`)
|
|
17
|
+
.setProtectedHeader({ alg, kid: props.appKeyId })
|
|
18
|
+
.sign(privateKey);
|
|
18
19
|
};
|
|
19
20
|
const serializePermissions = (permissions) => {
|
|
20
21
|
const result = [];
|
|
@@ -32,7 +33,7 @@ const serializePermissions = (permissions) => {
|
|
|
32
33
|
return result;
|
|
33
34
|
};
|
|
34
35
|
export const createTokenSigner = (options) => ({
|
|
35
|
-
createAccountToken: (props) => createToken({
|
|
36
|
+
createAccountToken: async (props) => createToken({
|
|
36
37
|
appKeyId: options.appKeyId,
|
|
37
38
|
appKeySecret: options.appKeySecret,
|
|
38
39
|
expiresInSeconds: props.expiresInSeconds,
|
|
@@ -42,13 +43,13 @@ export const createTokenSigner = (options) => ({
|
|
|
42
43
|
sub: props.accountId,
|
|
43
44
|
},
|
|
44
45
|
}),
|
|
45
|
-
createRootToken: (props) => createToken({
|
|
46
|
+
createRootToken: async (props) => createToken({
|
|
46
47
|
appKeyId: options.appKeyId,
|
|
47
48
|
appKeySecret: options.appKeySecret,
|
|
48
49
|
expiresInSeconds: props.expiresInSeconds ?? 3600,
|
|
49
50
|
payload: {
|
|
50
51
|
iss: options.appId,
|
|
51
|
-
permissions:
|
|
52
|
+
permissions: ['*'],
|
|
52
53
|
},
|
|
53
54
|
}),
|
|
54
55
|
});
|
|
@@ -16,21 +16,3 @@ export const defaultPermissions = {
|
|
|
16
16
|
stacks: { create: true, items: { add: true, remove: true }, read: true, metadata: { update: true } },
|
|
17
17
|
storage: { create: true, delete: true, read: true, update: true },
|
|
18
18
|
};
|
|
19
|
-
export const defaultRootPermissions = {
|
|
20
|
-
access: { add: true, read: true, remove: true },
|
|
21
|
-
accounts: { create: true, read: true },
|
|
22
|
-
balances: { read: true, self: { read: true, update: true }, update: true },
|
|
23
|
-
collections: {
|
|
24
|
-
create: true,
|
|
25
|
-
items: { add: true, read: true, remove: true },
|
|
26
|
-
read: true,
|
|
27
|
-
update: true,
|
|
28
|
-
},
|
|
29
|
-
groups: { accounts: { add: true, read: true, remove: true }, create: true, delete: true, read: true },
|
|
30
|
-
images: { create: true, read: true },
|
|
31
|
-
operations: { create: true, read: true, metadata: { update: true } },
|
|
32
|
-
pipelines: { create: true, read: true, update: true },
|
|
33
|
-
poses: { create: true, read: true },
|
|
34
|
-
stacks: { create: true, items: { add: true, remove: true }, read: true, metadata: { update: true } },
|
|
35
|
-
storage: { create: true, delete: true, read: true, update: true },
|
|
36
|
-
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hautechai/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"repository": {
|
|
@@ -19,8 +19,7 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@hautechai/pipelines": "0.1.0",
|
|
21
21
|
"axios": "1.6.1",
|
|
22
|
-
"
|
|
23
|
-
"jwt-decode": "4.0.0",
|
|
22
|
+
"jose": "5.9.6",
|
|
24
23
|
"pusher-js": "8.4.0-rc2"
|
|
25
24
|
},
|
|
26
25
|
"devDependencies": {
|