@dronedeploy/rocos-js-sdk 3.0.1-alpha.6 → 3.0.1-alpha.7
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/cjs/constants/api.d.ts +1 -0
- package/cjs/constants/api.js +2 -1
- package/cjs/helpers/getSha256Hex.d.ts +1 -0
- package/cjs/helpers/getSha256Hex.js +9 -0
- package/cjs/helpers/getSha256Hex.spec.d.ts +1 -0
- package/cjs/helpers/getSha256Hex.spec.js +19 -0
- package/cjs/helpers/getSha256HexNode.d.ts +1 -0
- package/cjs/helpers/getSha256HexNode.js +13 -0
- package/cjs/helpers/getSha256HexNode.spec.d.ts +1 -0
- package/cjs/helpers/getSha256HexNode.spec.js +10 -0
- package/cjs/models/workflow/Workflow.d.ts +69 -11
- package/cjs/node/RocosSDKNode.js +2 -1
- package/cjs/services/WorkflowService.d.ts +11 -16
- package/cjs/services/WorkflowService.js +32 -15
- package/cjs/services/WorkflowServiceNode.d.ts +4 -0
- package/cjs/services/WorkflowServiceNode.js +12 -0
- package/esm/constants/api.d.ts +1 -0
- package/esm/constants/api.js +1 -0
- package/esm/helpers/getSha256Hex.d.ts +1 -0
- package/esm/helpers/getSha256Hex.js +5 -0
- package/esm/helpers/getSha256Hex.spec.d.ts +1 -0
- package/esm/helpers/getSha256Hex.spec.js +14 -0
- package/esm/helpers/getSha256HexNode.d.ts +1 -0
- package/esm/helpers/getSha256HexNode.js +6 -0
- package/esm/helpers/getSha256HexNode.spec.d.ts +1 -0
- package/esm/helpers/getSha256HexNode.spec.js +8 -0
- package/esm/models/workflow/Workflow.d.ts +69 -11
- package/esm/node/RocosSDKNode.js +3 -2
- package/esm/services/WorkflowService.d.ts +11 -16
- package/esm/services/WorkflowService.js +33 -16
- package/esm/services/WorkflowServiceNode.d.ts +4 -0
- package/esm/services/WorkflowServiceNode.js +8 -0
- package/package.json +1 -1
package/cjs/constants/api.d.ts
CHANGED
@@ -130,4 +130,5 @@ export declare const API_OBSERVATIONS_URL = "https://{url}/projects/{projectId}/
|
|
130
130
|
export declare const API_OBSERVATION_KEYS_URL = "https://{url}/projects/{projectId}/observations/keys";
|
131
131
|
export declare const API_PROJECT_WORKFLOW_URL = "https://{url}/projects/{projectId}/automate/flows";
|
132
132
|
export declare const API_PROJECT_WORKFLOW_ID_URL = "https://{url}/projects/{projectId}/automate/flows/{workflowId}";
|
133
|
+
export declare const API_PROJECT_WORKFLOW_ASSET_URL = "https://{url}/projects/{projectId}/automate/flows/{workflowId}/assets";
|
133
134
|
export declare const API_PROJECT_DEPLOYED_WORKFLOW_URL = "https://{url}/projects/{projectId}/robots/{callsign}/automate/flows/deployments";
|
package/cjs/constants/api.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.API_PROJECT_ROBOT_REGISTER_URL = exports.API_PROJECT_ROBOT_DEFINITION_URL = exports.API_PROJECT_ROBOT_ATTRIBUTES_URL = exports.API_PROJECT_ROBOT_ID_URL = exports.API_PROJECT_ROBOT_URL = exports.API_PROJECT_MAPPED_ASSETS_PATH_URL = exports.API_PROJECT_MISSION_ASSET_PATH_URL = exports.API_PROJECT_MISSION_ASSETS_PATH_URL = exports.API_PROJECT_FLOW_ASSET_PATH_URL = exports.API_PROJECT_ROBOT_ASSET_PATH_URL = exports.API_PROJECT_ASSET_INTEGRATION_PATH_URL = exports.API_PROJECT_ASSET_INTEGRATIONS_PATH_URL = exports.API_PROJECT_ASSET_INTEGRATION_PROVIDERS_PATH_URL = exports.API_PROJECT_ASSET_PROFILES_SYNC_DEFINITION_PATH_URL = exports.API_PROJECT_ASSET_ROBOTS_SYNC_DEFINITION_PATH_URL = exports.API_PROJECT_ASSET_PATH_URL = exports.API_PROJECT_ASSET_URL = exports.API_PROJECT_USERS_URL = exports.API_PROJECT_ID_URL = exports.API_PROJECT_URL = exports.API_ACCOUNT_PROJECT_APPLICATION_ID_URL = exports.API_ACCOUNT_PROJECT_APPLICATION_URL = exports.API_ACCOUNT_PROJECT_USER_ID_URL = exports.API_ACCOUNT_PROJECT_USER_URL = exports.API_ACCOUNT_PROJECT_ID_URL = exports.API_ACCOUNT_PROJECT_URL = exports.API_SERVER_TIME_URL = exports.API_ACCOUNT_INTEGRATION_TYPE_URL = exports.API_ACCOUNT_INTEGRATION_URL = exports.API_ACCOUNT_SETTINGS_URL = exports.API_AUTH_USER_ACCOUNT_USER_ID_URL = exports.API_AUTH_USER_ACCOUNT_USER_URL = exports.API_ACCOUNT_ACTIVATE_URL = exports.API_ACCOUNT_ID_URL = exports.API_ACCOUNT_URL = exports.API_USER_PAT_TOKEN_URL = exports.API_USER_PAT_URL = exports.API_USER_VERIFY_EMAIL_URL = exports.API_USER_INVITATION_CHECK_URL = exports.API_USER_INVITATION_ACCEPT_URL = exports.API_USER_INVITATION_URL = exports.API_USER_PASSWORD_FORGOT_URL = exports.API_USER_PASSWORD_RESET_URL = exports.API_OTP_AUTH_URL = exports.API_OTP_URL = exports.API_USER_TOKEN_URL = exports.API_USER_AUTH_URL = exports.API_USER_URL = exports.API_ADMIN_USER_INVITATION_URL = exports.API_APPLICATION_AUTH_URL = void 0;
|
4
4
|
exports.API_PROJECT_STREAM_CALLSIGN_URL = exports.API_PROJECT_STREAM_DATA_URL = exports.API_PROJECT_STREAM_ID_URL = exports.API_PROJECT_STREAM_URL = exports.API_PROJECT_EXPORT_URL = exports.API_PROJECT_FUNCTION_POD_URL = exports.API_PROJECT_FUNCTION_RUN_URL = exports.API_PROJECT_FUNCTION_ID_URL = exports.API_PROJECT_FUNCTION_URL = exports.API_PROJECT_GROUP_TYPE_OWNER_OVERRIDE_URL = exports.API_PROJECT_GROUP_TYPE_OWNER_ID_URL = exports.API_PROJECT_GROUP_TYPE_VERSION_URL = exports.API_PROJECT_GROUP_TYPE_CONFIG_URL = exports.API_PROJECT_GROUP_TYPE_PUBLISH_URL = exports.API_PROJECT_GROUP_TYPE_ID_URL = exports.API_PROJECT_GROUP_TYPE_URL = exports.API_PROJECT_DEFINITION_GAMEPAD_URL = exports.API_PROJECT_DEFINITION_TRIGGER_URL = exports.API_PROJECT_DEFINITION_BUTTON_URL = exports.API_PROJECT_DEFINITION_ACTION_URL = exports.API_PROJECT_DEFINITION_EVENT_URL = exports.API_PROJECT_DEFINITION_COMMAND2_URL = exports.API_PROJECT_DEFINITION_COMMAND_URL = exports.API_PROJECT_DEFINITION_AGENT_URL = exports.API_PROJECT_DEFINITION_SETTING_URL = exports.API_PROJECT_DEFINITION_BLOB_URL = exports.API_PROJECT_DEFINITION_DASHBOARD_URL = exports.API_PROJECT_DEFINITION_COPY_URL = exports.API_PROJECT_DEFINITION_STREAM_URL = exports.API_PROJECT_DEFINITION_ID_URL = exports.API_PROJECT_DEFINITION_URL = exports.API_PROJECT_VROBOT_DEPLOY_URL = exports.API_PROJECT_VROBOT_DETAILS_URL = exports.API_PROJECT_COLLECTION_DOCS_URL = exports.API_PROJECT_COLLECTION_ID_URL = exports.API_PROJECT_DASHBOARD_CUSTOM_WIDGET_URL = exports.API_PROJECT_DASHBOARD_WIDGET_URL = exports.API_PROJECT_DASHBOARD_ID_URL = exports.API_PROJECT_DASHBOARD_URL = exports.API_PROJECT_OPERATION_ID_URL = exports.API_PROJECT_OPERATION_URL = exports.API_PROJECT_ROBOT_GAMEPAD_URL = exports.API_PROJECT_ROBOT_TRIGGER_URL = exports.API_PROJECT_ROBOT_BUTTON_URL = exports.API_PROJECT_ROBOT_COMMAND2_URL = exports.API_PROJECT_ROBOT_COMMAND_URL = exports.API_PROJECT_ROBOT_AGENT_URL = exports.API_PROJECT_ROBOT_SETTING_URL = exports.API_PROJECT_ROBOT_EVENT_HISTORY_URL = exports.API_PROJECT_ROBOT_EVENT_URL = void 0;
|
5
|
-
exports.API_PROJECT_DEPLOYED_WORKFLOW_URL = exports.API_PROJECT_WORKFLOW_ID_URL = exports.API_PROJECT_WORKFLOW_URL = exports.API_OBSERVATION_KEYS_URL = exports.API_OBSERVATIONS_URL = exports.API_MAPS_PANORAMA_OBSERVATIONS_URL = exports.API_MAPS_GEOJSON_URL = exports.API_MAPS_DEPLOY_URL = exports.API_MAPS_COPY_URL = exports.API_MAP_ID_URL = exports.API_MAPS_MERGE_URL = exports.API_MAPS_DEPLOYED_URL = exports.API_MAPS_URL = exports.API_DD_INTEGRATION_ISSUES_URL = exports.API_DD_INTEGRATION_OVERLAYS_URL = exports.API_DD_INTEGRATION_PLAN_BY_ID_URL = exports.API_DD_INTEGRATION_PLANS_URL = exports.API_SPOTTY_URL = exports.API_PROJECT_SCHEDULES_URL = exports.API_SOURCE_ID_URL = exports.API_SOURCE_URL = exports.API_SOURCE_SCHEMA_URL = exports.API_TEMPLATE_EXPORTER_URL = exports.API_TEMPLATE_PROVISION_ID_URL = exports.API_TEMPLATE_PROVISION_URL = exports.API_TEMPLATE_DEPLOY_URL = exports.API_PROJECT_PROFILE_DASHBOARD_CUSTOM_WIDGET_URL = exports.API_PROJECT_PROFILE_DASHBOARD_ID_URL = exports.API_PROJECT_PROFILE_DASHBOARD_URL = exports.API_PROJECT_CALLSIGN_STREAM_URL = exports.API_PROJECT_ROBOT_DASHBOARD_CUSTOM_WIDGET_URL = exports.API_PROJECT_ROBOT_DASHBOARD_ID_URL = exports.API_PROJECT_ROBOT_DASHBOARD_URL = void 0;
|
5
|
+
exports.API_PROJECT_DEPLOYED_WORKFLOW_URL = exports.API_PROJECT_WORKFLOW_ASSET_URL = exports.API_PROJECT_WORKFLOW_ID_URL = exports.API_PROJECT_WORKFLOW_URL = exports.API_OBSERVATION_KEYS_URL = exports.API_OBSERVATIONS_URL = exports.API_MAPS_PANORAMA_OBSERVATIONS_URL = exports.API_MAPS_GEOJSON_URL = exports.API_MAPS_DEPLOY_URL = exports.API_MAPS_COPY_URL = exports.API_MAP_ID_URL = exports.API_MAPS_MERGE_URL = exports.API_MAPS_DEPLOYED_URL = exports.API_MAPS_URL = exports.API_DD_INTEGRATION_ISSUES_URL = exports.API_DD_INTEGRATION_OVERLAYS_URL = exports.API_DD_INTEGRATION_PLAN_BY_ID_URL = exports.API_DD_INTEGRATION_PLANS_URL = exports.API_SPOTTY_URL = exports.API_PROJECT_SCHEDULES_URL = exports.API_SOURCE_ID_URL = exports.API_SOURCE_URL = exports.API_SOURCE_SCHEMA_URL = exports.API_TEMPLATE_EXPORTER_URL = exports.API_TEMPLATE_PROVISION_ID_URL = exports.API_TEMPLATE_PROVISION_URL = exports.API_TEMPLATE_DEPLOY_URL = exports.API_PROJECT_PROFILE_DASHBOARD_CUSTOM_WIDGET_URL = exports.API_PROJECT_PROFILE_DASHBOARD_ID_URL = exports.API_PROJECT_PROFILE_DASHBOARD_URL = exports.API_PROJECT_CALLSIGN_STREAM_URL = exports.API_PROJECT_ROBOT_DASHBOARD_CUSTOM_WIDGET_URL = exports.API_PROJECT_ROBOT_DASHBOARD_ID_URL = exports.API_PROJECT_ROBOT_DASHBOARD_URL = void 0;
|
6
6
|
exports.API_APPLICATION_AUTH_URL = 'https://{url}/applications/auth';
|
7
7
|
exports.API_ADMIN_USER_INVITATION_URL = 'https://{url}/admin/users/invitations';
|
8
8
|
exports.API_USER_URL = 'https://{url}/users';
|
@@ -135,4 +135,5 @@ exports.API_OBSERVATIONS_URL = 'https://{url}/projects/{projectId}/observations'
|
|
135
135
|
exports.API_OBSERVATION_KEYS_URL = 'https://{url}/projects/{projectId}/observations/keys';
|
136
136
|
exports.API_PROJECT_WORKFLOW_URL = 'https://{url}/projects/{projectId}/automate/flows';
|
137
137
|
exports.API_PROJECT_WORKFLOW_ID_URL = 'https://{url}/projects/{projectId}/automate/flows/{workflowId}';
|
138
|
+
exports.API_PROJECT_WORKFLOW_ASSET_URL = 'https://{url}/projects/{projectId}/automate/flows/{workflowId}/assets';
|
138
139
|
exports.API_PROJECT_DEPLOYED_WORKFLOW_URL = 'https://{url}/projects/{projectId}/robots/{callsign}/automate/flows/deployments';
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const getSha256Hex: (arrayBuffer: ArrayBuffer) => Promise<string>;
|
@@ -0,0 +1,9 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getSha256Hex = void 0;
|
4
|
+
const getSha256Hex = async (arrayBuffer) => {
|
5
|
+
const hashBuffer = await crypto.subtle.digest('SHA-256', arrayBuffer);
|
6
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
7
|
+
return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
|
8
|
+
};
|
9
|
+
exports.getSha256Hex = getSha256Hex;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,19 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const crypto_1 = __importDefault(require("crypto"));
|
7
|
+
const getSha256Hex_1 = require("./getSha256Hex");
|
8
|
+
Object.defineProperty(globalThis, 'crypto', {
|
9
|
+
value: {
|
10
|
+
subtle: crypto_1.default.webcrypto.subtle,
|
11
|
+
},
|
12
|
+
});
|
13
|
+
describe('getSha256Hex', () => {
|
14
|
+
it('should return the correct SHA-256 hash', async () => {
|
15
|
+
const buffer = new TextEncoder().encode('Hello, World!');
|
16
|
+
const hash = await (0, getSha256Hex_1.getSha256Hex)(buffer);
|
17
|
+
expect(hash).toBe('dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f');
|
18
|
+
});
|
19
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const getSha256HexNode: (arrayBuffer: ArrayBuffer) => Promise<string>;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.getSha256HexNode = void 0;
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
8
|
+
const getSha256HexNode = async (arrayBuffer) => {
|
9
|
+
const hashBuffer = await crypto_1.default.subtle.digest('SHA-256', arrayBuffer);
|
10
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
11
|
+
return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
|
12
|
+
};
|
13
|
+
exports.getSha256HexNode = getSha256HexNode;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const getSha256HexNode_1 = require("./getSha256HexNode");
|
4
|
+
describe('getSha256HexNode', () => {
|
5
|
+
it('should return the correct SHA-256 hash', async () => {
|
6
|
+
const buffer = new TextEncoder().encode('Hello, World!');
|
7
|
+
const hash = await (0, getSha256HexNode_1.getSha256HexNode)(buffer);
|
8
|
+
expect(hash).toBe('dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f');
|
9
|
+
});
|
10
|
+
});
|
@@ -1,12 +1,12 @@
|
|
1
|
-
export type ResourceType = 'Manifest' | 'AgentGraph' | 'Javascript' | 'NodeDefinition';
|
1
|
+
export type ResourceType = 'Manifest' | 'AgentGraph' | 'Javascript' | 'NodeDefinition' | 'Other';
|
2
2
|
export interface Resource {
|
3
3
|
type: ResourceType;
|
4
4
|
data: string;
|
5
|
-
contentLink: string;
|
6
5
|
hash: string;
|
7
6
|
link: string;
|
8
|
-
|
9
|
-
size
|
7
|
+
contentLink?: string;
|
8
|
+
size?: number;
|
9
|
+
path?: string;
|
10
10
|
}
|
11
11
|
export interface Resources {
|
12
12
|
[key: string]: Resource;
|
@@ -16,21 +16,79 @@ export interface Author {
|
|
16
16
|
name: string;
|
17
17
|
email: string;
|
18
18
|
}
|
19
|
+
interface ResponseBase {
|
20
|
+
id: string;
|
21
|
+
createdBy: string;
|
22
|
+
updatedBy: string;
|
23
|
+
dateCreated: number;
|
24
|
+
dateUpdated: number;
|
25
|
+
}
|
19
26
|
export interface WorkflowBase {
|
20
27
|
flowId: string;
|
21
28
|
name: string;
|
22
|
-
description
|
29
|
+
description?: string;
|
23
30
|
resources?: Resources;
|
24
31
|
type?: string;
|
25
32
|
}
|
26
|
-
export interface Workflow extends WorkflowBase {
|
27
|
-
id: string;
|
33
|
+
export interface Workflow extends WorkflowBase, ResponseBase {
|
28
34
|
projectId: string;
|
29
|
-
createdBy: string;
|
30
|
-
updatedBy: string;
|
31
35
|
author: Author;
|
32
|
-
dateCreated: number;
|
33
|
-
dateUpdated: number;
|
34
36
|
latestVersion: string;
|
35
37
|
type: string;
|
36
38
|
}
|
39
|
+
export interface DeployedFlow {
|
40
|
+
flowId: string;
|
41
|
+
flow?: Workflow;
|
42
|
+
deployed?: boolean;
|
43
|
+
}
|
44
|
+
export interface WorkflowList extends Omit<WorkflowBase, 'resources'>, ResponseBase {
|
45
|
+
type?: 'cloud';
|
46
|
+
author: {
|
47
|
+
id: string;
|
48
|
+
name: string;
|
49
|
+
email: string;
|
50
|
+
} | Record<string, never>;
|
51
|
+
}
|
52
|
+
export interface WorkflowRevision {
|
53
|
+
id: string;
|
54
|
+
version: number;
|
55
|
+
authorName: string;
|
56
|
+
createdBy: string;
|
57
|
+
dateCreated: number;
|
58
|
+
description: string;
|
59
|
+
selected?: boolean;
|
60
|
+
}
|
61
|
+
export interface ManifestResource {
|
62
|
+
path: string;
|
63
|
+
provider: string;
|
64
|
+
runtime: string;
|
65
|
+
options: string[];
|
66
|
+
}
|
67
|
+
export interface ManifestArgument {
|
68
|
+
default?: string;
|
69
|
+
description?: string;
|
70
|
+
type: string;
|
71
|
+
}
|
72
|
+
export interface Manifest {
|
73
|
+
main: [string, string];
|
74
|
+
signals?: {
|
75
|
+
main: {
|
76
|
+
args: string[];
|
77
|
+
entry: [string, string];
|
78
|
+
};
|
79
|
+
};
|
80
|
+
arguments?: unknown | Record<string, ManifestArgument>;
|
81
|
+
resources: ManifestResource[];
|
82
|
+
mode?: 'cloud';
|
83
|
+
}
|
84
|
+
export interface CreateAssetResponse {
|
85
|
+
id: string;
|
86
|
+
name: string;
|
87
|
+
path: string;
|
88
|
+
dateCreated: number;
|
89
|
+
hash: string;
|
90
|
+
postContentLink: string;
|
91
|
+
type: 'file';
|
92
|
+
workflow: string;
|
93
|
+
}
|
94
|
+
export {};
|
package/cjs/node/RocosSDKNode.js
CHANGED
@@ -10,6 +10,7 @@ const FileAccessorServiceNode_1 = require("../services/FileAccessorServiceNode")
|
|
10
10
|
const RocosSDK_1 = require("../RocosSDK");
|
11
11
|
const SearchServiceNode_1 = require("../services/SearchServiceNode");
|
12
12
|
const TelemetryServiceNode_1 = require("../services/TelemetryServiceNode");
|
13
|
+
const WorkflowServiceNode_1 = require("../services/WorkflowServiceNode");
|
13
14
|
class RocosSDKNode extends RocosSDK_1.RocosSDK {
|
14
15
|
// eslint-disable-next-line max-lines-per-function
|
15
16
|
getService(name) {
|
@@ -60,7 +61,7 @@ class RocosSDKNode extends RocosSDK_1.RocosSDK {
|
|
60
61
|
this.services[name] = new services_1.UserService(config);
|
61
62
|
break;
|
62
63
|
case models_1.ServiceEnum.WORKFLOW:
|
63
|
-
this.services[name] = new
|
64
|
+
this.services[name] = new WorkflowServiceNode_1.WorkflowServiceNode(config);
|
64
65
|
break;
|
65
66
|
case models_1.ServiceEnum.ASSET_STORAGE:
|
66
67
|
this.services[name] = new services_1.AssetStorageService(config);
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { RocosError } from '../models/RocosError';
|
2
1
|
import type { Workflow, WorkflowBase } from '../models/workflow/Workflow';
|
2
|
+
import { RocosError } from '../models/RocosError';
|
3
3
|
import { BaseServiceAbstract } from './BaseServiceAbstract';
|
4
4
|
import { IBaseService } from '../models/IBaseService';
|
5
5
|
import { IRocosSDKConfig } from '../models/IRocosSDKConfig';
|
@@ -13,11 +13,6 @@ export declare class WorkflowService extends BaseServiceAbstract implements IBas
|
|
13
13
|
* @param projectId - Project Id
|
14
14
|
*/
|
15
15
|
list(projectId: string): Promise<Workflow[]>;
|
16
|
-
/**
|
17
|
-
* @deprecated This method is deprecated and will be removed in a future version.
|
18
|
-
* Use list instead.
|
19
|
-
*/
|
20
|
-
getAll: (projectId: string) => Promise<Workflow[]>;
|
21
16
|
/**
|
22
17
|
* Create a workflow
|
23
18
|
*
|
@@ -32,11 +27,6 @@ export declare class WorkflowService extends BaseServiceAbstract implements IBas
|
|
32
27
|
* @param workflowId - Workflow Id
|
33
28
|
*/
|
34
29
|
get(projectId: string, workflowId: string): Promise<Workflow>;
|
35
|
-
/**
|
36
|
-
* @deprecated This method is deprecated and will be removed in a future version.
|
37
|
-
* Use get instead.
|
38
|
-
*/
|
39
|
-
getOne: (projectId: string, workflowId: string) => Promise<Workflow>;
|
40
30
|
/**
|
41
31
|
* Update a workflow
|
42
32
|
*
|
@@ -45,6 +35,16 @@ export declare class WorkflowService extends BaseServiceAbstract implements IBas
|
|
45
35
|
* @param model - Workflow
|
46
36
|
*/
|
47
37
|
update(projectId: string, workflowId: string, model: Workflow): Promise<Workflow>;
|
38
|
+
/**
|
39
|
+
* Upload workflow asset
|
40
|
+
*
|
41
|
+
* @param projectId - Project Id
|
42
|
+
* @param workflowId - Workflow Id
|
43
|
+
* @param fileName - Name of file including extension
|
44
|
+
* @param arrayBuffer - data to upload
|
45
|
+
*/
|
46
|
+
uploadAsset(projectId: string, workflowId: string, fileName: string, arrayBuffer: ArrayBuffer): Promise<void>;
|
47
|
+
protected uploadAssetWithHash(projectId: string, workflowId: string, fileName: string, arrayBuffer: ArrayBuffer, hash: string): Promise<void>;
|
48
48
|
/**
|
49
49
|
* Delete a workflow
|
50
50
|
*
|
@@ -59,9 +59,4 @@ export declare class WorkflowService extends BaseServiceAbstract implements IBas
|
|
59
59
|
* @param callsign - Robot callsign
|
60
60
|
*/
|
61
61
|
getDeployedWorkflows(projectId: string, callsign: string): Promise<Workflow[]>;
|
62
|
-
/**
|
63
|
-
* @deprecated This method is deprecated and will be removed in a future version.
|
64
|
-
* Use getDeployedWorkflow instead.
|
65
|
-
*/
|
66
|
-
getDeployedOnRobot: (projectId: string, callsign: string) => Promise<Workflow[]>;
|
67
62
|
}
|
@@ -6,24 +6,10 @@ const RocosError_1 = require("../models/RocosError");
|
|
6
6
|
const BaseServiceAbstract_1 = require("./BaseServiceAbstract");
|
7
7
|
const RocosLogger_1 = require("../logger/RocosLogger");
|
8
8
|
const formatServiceUrl_1 = require("../helpers/formatServiceUrl");
|
9
|
+
const getSha256Hex_1 = require("../helpers/getSha256Hex");
|
9
10
|
class WorkflowService extends BaseServiceAbstract_1.BaseServiceAbstract {
|
10
11
|
constructor(config) {
|
11
12
|
super(config);
|
12
|
-
/**
|
13
|
-
* @deprecated This method is deprecated and will be removed in a future version.
|
14
|
-
* Use list instead.
|
15
|
-
*/
|
16
|
-
this.getAll = this.list;
|
17
|
-
/**
|
18
|
-
* @deprecated This method is deprecated and will be removed in a future version.
|
19
|
-
* Use get instead.
|
20
|
-
*/
|
21
|
-
this.getOne = this.get;
|
22
|
-
/**
|
23
|
-
* @deprecated This method is deprecated and will be removed in a future version.
|
24
|
-
* Use getDeployedWorkflow instead.
|
25
|
-
*/
|
26
|
-
this.getDeployedOnRobot = this.getDeployedWorkflows;
|
27
13
|
this.logger = RocosLogger_1.RocosLogger.getInstance(`WorkflowService(${this.config.url})`);
|
28
14
|
}
|
29
15
|
getError(e) {
|
@@ -68,6 +54,37 @@ class WorkflowService extends BaseServiceAbstract_1.BaseServiceAbstract {
|
|
68
54
|
async update(projectId, workflowId, model) {
|
69
55
|
return this.callPut((0, formatServiceUrl_1.formatServiceUrl)(api_1.API_PROJECT_WORKFLOW_ID_URL, { url: this.config.url, projectId, workflowId }, this.config.insecure), model, `Failed to update workflow for ${projectId}, workflowId ${workflowId}.`);
|
70
56
|
}
|
57
|
+
/**
|
58
|
+
* Upload workflow asset
|
59
|
+
*
|
60
|
+
* @param projectId - Project Id
|
61
|
+
* @param workflowId - Workflow Id
|
62
|
+
* @param fileName - Name of file including extension
|
63
|
+
* @param arrayBuffer - data to upload
|
64
|
+
*/
|
65
|
+
async uploadAsset(projectId, workflowId, fileName, arrayBuffer) {
|
66
|
+
const hash = await (0, getSha256Hex_1.getSha256Hex)(arrayBuffer);
|
67
|
+
return this.uploadAssetWithHash(projectId, workflowId, fileName, arrayBuffer, hash);
|
68
|
+
}
|
69
|
+
async uploadAssetWithHash(projectId, workflowId, fileName, arrayBuffer, hash) {
|
70
|
+
// Get asset upload link
|
71
|
+
const createAssetResponse = await this.callPost((0, formatServiceUrl_1.formatServiceUrl)(api_1.API_PROJECT_WORKFLOW_ASSET_URL, { url: this.config.url, projectId, workflowId }, this.config.insecure), { name: fileName, type: 'file', hash }, `Failed to create asset for ${projectId}, workflowId ${workflowId}.`);
|
72
|
+
const { postContentLink } = createAssetResponse;
|
73
|
+
if (!postContentLink)
|
74
|
+
throw new Error('postContentLink is undefined');
|
75
|
+
// Get Google upload location
|
76
|
+
const postFileResponse = await fetch(postContentLink, {
|
77
|
+
method: 'POST',
|
78
|
+
headers: { 'x-goog-resumable': 'start' },
|
79
|
+
});
|
80
|
+
const putLocation = postFileResponse.headers.get('location');
|
81
|
+
if (!putLocation)
|
82
|
+
throw new Error('putLocation is undefined');
|
83
|
+
// Upload file to Google
|
84
|
+
const uploadResponse = await fetch(putLocation, { method: 'PUT', body: arrayBuffer });
|
85
|
+
if (uploadResponse.status !== 200)
|
86
|
+
throw new Error(`Failed to upload file: ${uploadResponse.statusText}`);
|
87
|
+
}
|
71
88
|
/**
|
72
89
|
* Delete a workflow
|
73
90
|
*
|
@@ -0,0 +1,12 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.WorkflowServiceNode = void 0;
|
4
|
+
const WorkflowService_1 = require("./WorkflowService");
|
5
|
+
const getSha256HexNode_1 = require("../helpers/getSha256HexNode");
|
6
|
+
class WorkflowServiceNode extends WorkflowService_1.WorkflowService {
|
7
|
+
async uploadAsset(projectId, workflowId, fileName, arrayBuffer) {
|
8
|
+
const hash = await (0, getSha256HexNode_1.getSha256HexNode)(arrayBuffer);
|
9
|
+
return this.uploadAssetWithHash(projectId, workflowId, fileName, arrayBuffer, hash);
|
10
|
+
}
|
11
|
+
}
|
12
|
+
exports.WorkflowServiceNode = WorkflowServiceNode;
|
package/esm/constants/api.d.ts
CHANGED
@@ -130,4 +130,5 @@ export declare const API_OBSERVATIONS_URL = "https://{url}/projects/{projectId}/
|
|
130
130
|
export declare const API_OBSERVATION_KEYS_URL = "https://{url}/projects/{projectId}/observations/keys";
|
131
131
|
export declare const API_PROJECT_WORKFLOW_URL = "https://{url}/projects/{projectId}/automate/flows";
|
132
132
|
export declare const API_PROJECT_WORKFLOW_ID_URL = "https://{url}/projects/{projectId}/automate/flows/{workflowId}";
|
133
|
+
export declare const API_PROJECT_WORKFLOW_ASSET_URL = "https://{url}/projects/{projectId}/automate/flows/{workflowId}/assets";
|
133
134
|
export declare const API_PROJECT_DEPLOYED_WORKFLOW_URL = "https://{url}/projects/{projectId}/robots/{callsign}/automate/flows/deployments";
|
package/esm/constants/api.js
CHANGED
@@ -130,4 +130,5 @@ export const API_OBSERVATIONS_URL = 'https://{url}/projects/{projectId}/observat
|
|
130
130
|
export const API_OBSERVATION_KEYS_URL = 'https://{url}/projects/{projectId}/observations/keys';
|
131
131
|
export const API_PROJECT_WORKFLOW_URL = 'https://{url}/projects/{projectId}/automate/flows';
|
132
132
|
export const API_PROJECT_WORKFLOW_ID_URL = 'https://{url}/projects/{projectId}/automate/flows/{workflowId}';
|
133
|
+
export const API_PROJECT_WORKFLOW_ASSET_URL = 'https://{url}/projects/{projectId}/automate/flows/{workflowId}/assets';
|
133
134
|
export const API_PROJECT_DEPLOYED_WORKFLOW_URL = 'https://{url}/projects/{projectId}/robots/{callsign}/automate/flows/deployments';
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const getSha256Hex: (arrayBuffer: ArrayBuffer) => Promise<string>;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import crypto from 'crypto';
|
2
|
+
import { getSha256Hex } from './getSha256Hex';
|
3
|
+
Object.defineProperty(globalThis, 'crypto', {
|
4
|
+
value: {
|
5
|
+
subtle: crypto.webcrypto.subtle,
|
6
|
+
},
|
7
|
+
});
|
8
|
+
describe('getSha256Hex', () => {
|
9
|
+
it('should return the correct SHA-256 hash', async () => {
|
10
|
+
const buffer = new TextEncoder().encode('Hello, World!');
|
11
|
+
const hash = await getSha256Hex(buffer);
|
12
|
+
expect(hash).toBe('dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f');
|
13
|
+
});
|
14
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const getSha256HexNode: (arrayBuffer: ArrayBuffer) => Promise<string>;
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import crypto from 'crypto';
|
2
|
+
export const getSha256HexNode = async (arrayBuffer) => {
|
3
|
+
const hashBuffer = await crypto.subtle.digest('SHA-256', arrayBuffer);
|
4
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
5
|
+
return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
|
6
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { getSha256HexNode } from './getSha256HexNode';
|
2
|
+
describe('getSha256HexNode', () => {
|
3
|
+
it('should return the correct SHA-256 hash', async () => {
|
4
|
+
const buffer = new TextEncoder().encode('Hello, World!');
|
5
|
+
const hash = await getSha256HexNode(buffer);
|
6
|
+
expect(hash).toBe('dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f');
|
7
|
+
});
|
8
|
+
});
|
@@ -1,12 +1,12 @@
|
|
1
|
-
export type ResourceType = 'Manifest' | 'AgentGraph' | 'Javascript' | 'NodeDefinition';
|
1
|
+
export type ResourceType = 'Manifest' | 'AgentGraph' | 'Javascript' | 'NodeDefinition' | 'Other';
|
2
2
|
export interface Resource {
|
3
3
|
type: ResourceType;
|
4
4
|
data: string;
|
5
|
-
contentLink: string;
|
6
5
|
hash: string;
|
7
6
|
link: string;
|
8
|
-
|
9
|
-
size
|
7
|
+
contentLink?: string;
|
8
|
+
size?: number;
|
9
|
+
path?: string;
|
10
10
|
}
|
11
11
|
export interface Resources {
|
12
12
|
[key: string]: Resource;
|
@@ -16,21 +16,79 @@ export interface Author {
|
|
16
16
|
name: string;
|
17
17
|
email: string;
|
18
18
|
}
|
19
|
+
interface ResponseBase {
|
20
|
+
id: string;
|
21
|
+
createdBy: string;
|
22
|
+
updatedBy: string;
|
23
|
+
dateCreated: number;
|
24
|
+
dateUpdated: number;
|
25
|
+
}
|
19
26
|
export interface WorkflowBase {
|
20
27
|
flowId: string;
|
21
28
|
name: string;
|
22
|
-
description
|
29
|
+
description?: string;
|
23
30
|
resources?: Resources;
|
24
31
|
type?: string;
|
25
32
|
}
|
26
|
-
export interface Workflow extends WorkflowBase {
|
27
|
-
id: string;
|
33
|
+
export interface Workflow extends WorkflowBase, ResponseBase {
|
28
34
|
projectId: string;
|
29
|
-
createdBy: string;
|
30
|
-
updatedBy: string;
|
31
35
|
author: Author;
|
32
|
-
dateCreated: number;
|
33
|
-
dateUpdated: number;
|
34
36
|
latestVersion: string;
|
35
37
|
type: string;
|
36
38
|
}
|
39
|
+
export interface DeployedFlow {
|
40
|
+
flowId: string;
|
41
|
+
flow?: Workflow;
|
42
|
+
deployed?: boolean;
|
43
|
+
}
|
44
|
+
export interface WorkflowList extends Omit<WorkflowBase, 'resources'>, ResponseBase {
|
45
|
+
type?: 'cloud';
|
46
|
+
author: {
|
47
|
+
id: string;
|
48
|
+
name: string;
|
49
|
+
email: string;
|
50
|
+
} | Record<string, never>;
|
51
|
+
}
|
52
|
+
export interface WorkflowRevision {
|
53
|
+
id: string;
|
54
|
+
version: number;
|
55
|
+
authorName: string;
|
56
|
+
createdBy: string;
|
57
|
+
dateCreated: number;
|
58
|
+
description: string;
|
59
|
+
selected?: boolean;
|
60
|
+
}
|
61
|
+
export interface ManifestResource {
|
62
|
+
path: string;
|
63
|
+
provider: string;
|
64
|
+
runtime: string;
|
65
|
+
options: string[];
|
66
|
+
}
|
67
|
+
export interface ManifestArgument {
|
68
|
+
default?: string;
|
69
|
+
description?: string;
|
70
|
+
type: string;
|
71
|
+
}
|
72
|
+
export interface Manifest {
|
73
|
+
main: [string, string];
|
74
|
+
signals?: {
|
75
|
+
main: {
|
76
|
+
args: string[];
|
77
|
+
entry: [string, string];
|
78
|
+
};
|
79
|
+
};
|
80
|
+
arguments?: unknown | Record<string, ManifestArgument>;
|
81
|
+
resources: ManifestResource[];
|
82
|
+
mode?: 'cloud';
|
83
|
+
}
|
84
|
+
export interface CreateAssetResponse {
|
85
|
+
id: string;
|
86
|
+
name: string;
|
87
|
+
path: string;
|
88
|
+
dateCreated: number;
|
89
|
+
hash: string;
|
90
|
+
postContentLink: string;
|
91
|
+
type: 'file';
|
92
|
+
workflow: string;
|
93
|
+
}
|
94
|
+
export {};
|
package/esm/node/RocosSDKNode.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { AssetStorageService, AuthService, ConfigGroupService, DashboardService, EventService, FunctionService, IntegrationService, MapService, ProfileService, ProjectService, RobotService, ScheduleService, SpotProvisioningServiceNode, StreamService, UserService,
|
1
|
+
import { AssetStorageService, AuthService, ConfigGroupService, DashboardService, EventService, FunctionService, IntegrationService, MapService, ProfileService, ProjectService, RobotService, ScheduleService, SpotProvisioningServiceNode, StreamService, UserService, } from '../services';
|
2
2
|
import { ServiceEnum } from '../models';
|
3
3
|
import { CallerServiceNode } from '../services/CallerServiceNode';
|
4
4
|
import { CommandServiceNode } from '../services/CommandServiceNode';
|
@@ -7,6 +7,7 @@ import { FileAccessorServiceNode } from '../services/FileAccessorServiceNode';
|
|
7
7
|
import { RocosSDK } from '../RocosSDK';
|
8
8
|
import { SearchServiceNode } from '../services/SearchServiceNode';
|
9
9
|
import { TelemetryServiceNode } from '../services/TelemetryServiceNode';
|
10
|
+
import { WorkflowServiceNode } from '../services/WorkflowServiceNode';
|
10
11
|
export class RocosSDKNode extends RocosSDK {
|
11
12
|
// eslint-disable-next-line max-lines-per-function
|
12
13
|
getService(name) {
|
@@ -57,7 +58,7 @@ export class RocosSDKNode extends RocosSDK {
|
|
57
58
|
this.services[name] = new UserService(config);
|
58
59
|
break;
|
59
60
|
case ServiceEnum.WORKFLOW:
|
60
|
-
this.services[name] = new
|
61
|
+
this.services[name] = new WorkflowServiceNode(config);
|
61
62
|
break;
|
62
63
|
case ServiceEnum.ASSET_STORAGE:
|
63
64
|
this.services[name] = new AssetStorageService(config);
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { RocosError } from '../models/RocosError';
|
2
1
|
import type { Workflow, WorkflowBase } from '../models/workflow/Workflow';
|
2
|
+
import { RocosError } from '../models/RocosError';
|
3
3
|
import { BaseServiceAbstract } from './BaseServiceAbstract';
|
4
4
|
import { IBaseService } from '../models/IBaseService';
|
5
5
|
import { IRocosSDKConfig } from '../models/IRocosSDKConfig';
|
@@ -13,11 +13,6 @@ export declare class WorkflowService extends BaseServiceAbstract implements IBas
|
|
13
13
|
* @param projectId - Project Id
|
14
14
|
*/
|
15
15
|
list(projectId: string): Promise<Workflow[]>;
|
16
|
-
/**
|
17
|
-
* @deprecated This method is deprecated and will be removed in a future version.
|
18
|
-
* Use list instead.
|
19
|
-
*/
|
20
|
-
getAll: (projectId: string) => Promise<Workflow[]>;
|
21
16
|
/**
|
22
17
|
* Create a workflow
|
23
18
|
*
|
@@ -32,11 +27,6 @@ export declare class WorkflowService extends BaseServiceAbstract implements IBas
|
|
32
27
|
* @param workflowId - Workflow Id
|
33
28
|
*/
|
34
29
|
get(projectId: string, workflowId: string): Promise<Workflow>;
|
35
|
-
/**
|
36
|
-
* @deprecated This method is deprecated and will be removed in a future version.
|
37
|
-
* Use get instead.
|
38
|
-
*/
|
39
|
-
getOne: (projectId: string, workflowId: string) => Promise<Workflow>;
|
40
30
|
/**
|
41
31
|
* Update a workflow
|
42
32
|
*
|
@@ -45,6 +35,16 @@ export declare class WorkflowService extends BaseServiceAbstract implements IBas
|
|
45
35
|
* @param model - Workflow
|
46
36
|
*/
|
47
37
|
update(projectId: string, workflowId: string, model: Workflow): Promise<Workflow>;
|
38
|
+
/**
|
39
|
+
* Upload workflow asset
|
40
|
+
*
|
41
|
+
* @param projectId - Project Id
|
42
|
+
* @param workflowId - Workflow Id
|
43
|
+
* @param fileName - Name of file including extension
|
44
|
+
* @param arrayBuffer - data to upload
|
45
|
+
*/
|
46
|
+
uploadAsset(projectId: string, workflowId: string, fileName: string, arrayBuffer: ArrayBuffer): Promise<void>;
|
47
|
+
protected uploadAssetWithHash(projectId: string, workflowId: string, fileName: string, arrayBuffer: ArrayBuffer, hash: string): Promise<void>;
|
48
48
|
/**
|
49
49
|
* Delete a workflow
|
50
50
|
*
|
@@ -59,9 +59,4 @@ export declare class WorkflowService extends BaseServiceAbstract implements IBas
|
|
59
59
|
* @param callsign - Robot callsign
|
60
60
|
*/
|
61
61
|
getDeployedWorkflows(projectId: string, callsign: string): Promise<Workflow[]>;
|
62
|
-
/**
|
63
|
-
* @deprecated This method is deprecated and will be removed in a future version.
|
64
|
-
* Use getDeployedWorkflow instead.
|
65
|
-
*/
|
66
|
-
getDeployedOnRobot: (projectId: string, callsign: string) => Promise<Workflow[]>;
|
67
62
|
}
|
@@ -1,26 +1,12 @@
|
|
1
|
-
import { API_PROJECT_DEPLOYED_WORKFLOW_URL, API_PROJECT_WORKFLOW_ID_URL, API_PROJECT_WORKFLOW_URL, } from '../constants/api';
|
1
|
+
import { API_PROJECT_DEPLOYED_WORKFLOW_URL, API_PROJECT_WORKFLOW_ASSET_URL, API_PROJECT_WORKFLOW_ID_URL, API_PROJECT_WORKFLOW_URL, } from '../constants/api';
|
2
2
|
import { RocosError, errorCodes } from '../models/RocosError';
|
3
3
|
import { BaseServiceAbstract } from './BaseServiceAbstract';
|
4
4
|
import { RocosLogger } from '../logger/RocosLogger';
|
5
5
|
import { formatServiceUrl } from '../helpers/formatServiceUrl';
|
6
|
+
import { getSha256Hex } from '../helpers/getSha256Hex';
|
6
7
|
export class WorkflowService extends BaseServiceAbstract {
|
7
8
|
constructor(config) {
|
8
9
|
super(config);
|
9
|
-
/**
|
10
|
-
* @deprecated This method is deprecated and will be removed in a future version.
|
11
|
-
* Use list instead.
|
12
|
-
*/
|
13
|
-
this.getAll = this.list;
|
14
|
-
/**
|
15
|
-
* @deprecated This method is deprecated and will be removed in a future version.
|
16
|
-
* Use get instead.
|
17
|
-
*/
|
18
|
-
this.getOne = this.get;
|
19
|
-
/**
|
20
|
-
* @deprecated This method is deprecated and will be removed in a future version.
|
21
|
-
* Use getDeployedWorkflow instead.
|
22
|
-
*/
|
23
|
-
this.getDeployedOnRobot = this.getDeployedWorkflows;
|
24
10
|
this.logger = RocosLogger.getInstance(`WorkflowService(${this.config.url})`);
|
25
11
|
}
|
26
12
|
getError(e) {
|
@@ -65,6 +51,37 @@ export class WorkflowService extends BaseServiceAbstract {
|
|
65
51
|
async update(projectId, workflowId, model) {
|
66
52
|
return this.callPut(formatServiceUrl(API_PROJECT_WORKFLOW_ID_URL, { url: this.config.url, projectId, workflowId }, this.config.insecure), model, `Failed to update workflow for ${projectId}, workflowId ${workflowId}.`);
|
67
53
|
}
|
54
|
+
/**
|
55
|
+
* Upload workflow asset
|
56
|
+
*
|
57
|
+
* @param projectId - Project Id
|
58
|
+
* @param workflowId - Workflow Id
|
59
|
+
* @param fileName - Name of file including extension
|
60
|
+
* @param arrayBuffer - data to upload
|
61
|
+
*/
|
62
|
+
async uploadAsset(projectId, workflowId, fileName, arrayBuffer) {
|
63
|
+
const hash = await getSha256Hex(arrayBuffer);
|
64
|
+
return this.uploadAssetWithHash(projectId, workflowId, fileName, arrayBuffer, hash);
|
65
|
+
}
|
66
|
+
async uploadAssetWithHash(projectId, workflowId, fileName, arrayBuffer, hash) {
|
67
|
+
// Get asset upload link
|
68
|
+
const createAssetResponse = await this.callPost(formatServiceUrl(API_PROJECT_WORKFLOW_ASSET_URL, { url: this.config.url, projectId, workflowId }, this.config.insecure), { name: fileName, type: 'file', hash }, `Failed to create asset for ${projectId}, workflowId ${workflowId}.`);
|
69
|
+
const { postContentLink } = createAssetResponse;
|
70
|
+
if (!postContentLink)
|
71
|
+
throw new Error('postContentLink is undefined');
|
72
|
+
// Get Google upload location
|
73
|
+
const postFileResponse = await fetch(postContentLink, {
|
74
|
+
method: 'POST',
|
75
|
+
headers: { 'x-goog-resumable': 'start' },
|
76
|
+
});
|
77
|
+
const putLocation = postFileResponse.headers.get('location');
|
78
|
+
if (!putLocation)
|
79
|
+
throw new Error('putLocation is undefined');
|
80
|
+
// Upload file to Google
|
81
|
+
const uploadResponse = await fetch(putLocation, { method: 'PUT', body: arrayBuffer });
|
82
|
+
if (uploadResponse.status !== 200)
|
83
|
+
throw new Error(`Failed to upload file: ${uploadResponse.statusText}`);
|
84
|
+
}
|
68
85
|
/**
|
69
86
|
* Delete a workflow
|
70
87
|
*
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { WorkflowService } from './WorkflowService';
|
2
|
+
import { getSha256HexNode } from '../helpers/getSha256HexNode';
|
3
|
+
export class WorkflowServiceNode extends WorkflowService {
|
4
|
+
async uploadAsset(projectId, workflowId, fileName, arrayBuffer) {
|
5
|
+
const hash = await getSha256HexNode(arrayBuffer);
|
6
|
+
return this.uploadAssetWithHash(projectId, workflowId, fileName, arrayBuffer, hash);
|
7
|
+
}
|
8
|
+
}
|