@dronedeploy/rocos-js-sdk 3.0.1-alpha.6 → 3.0.1-alpha.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. package/cjs/constants/api.d.ts +2 -0
  2. package/cjs/constants/api.js +3 -1
  3. package/cjs/helpers/getSha256Hex.d.ts +1 -0
  4. package/cjs/helpers/getSha256Hex.js +9 -0
  5. package/cjs/helpers/getSha256Hex.spec.d.ts +1 -0
  6. package/cjs/helpers/getSha256Hex.spec.js +19 -0
  7. package/cjs/helpers/getSha256HexNode.d.ts +1 -0
  8. package/cjs/helpers/getSha256HexNode.js +13 -0
  9. package/cjs/helpers/getSha256HexNode.spec.d.ts +1 -0
  10. package/cjs/helpers/getSha256HexNode.spec.js +10 -0
  11. package/cjs/models/HttpError.d.ts +5 -0
  12. package/cjs/models/HttpError.js +12 -0
  13. package/cjs/models/IProject.d.ts +2 -0
  14. package/cjs/models/IProjectInfo.d.ts +14 -0
  15. package/cjs/models/IProjectInfo.js +2 -0
  16. package/cjs/models/index.d.ts +2 -0
  17. package/cjs/models/index.js +2 -0
  18. package/cjs/models/workflow/Workflow.d.ts +69 -11
  19. package/cjs/node/RocosSDKNode.js +2 -1
  20. package/cjs/services/BaseServiceAbstract.js +2 -9
  21. package/cjs/services/ProjectService.d.ts +5 -9
  22. package/cjs/services/ProjectService.js +5 -2
  23. package/cjs/services/WorkflowService.d.ts +11 -16
  24. package/cjs/services/WorkflowService.js +32 -15
  25. package/cjs/services/WorkflowServiceNode.d.ts +4 -0
  26. package/cjs/services/WorkflowServiceNode.js +12 -0
  27. package/esm/constants/api.d.ts +2 -0
  28. package/esm/constants/api.js +2 -0
  29. package/esm/helpers/getSha256Hex.d.ts +1 -0
  30. package/esm/helpers/getSha256Hex.js +5 -0
  31. package/esm/helpers/getSha256Hex.spec.d.ts +1 -0
  32. package/esm/helpers/getSha256Hex.spec.js +14 -0
  33. package/esm/helpers/getSha256HexNode.d.ts +1 -0
  34. package/esm/helpers/getSha256HexNode.js +6 -0
  35. package/esm/helpers/getSha256HexNode.spec.d.ts +1 -0
  36. package/esm/helpers/getSha256HexNode.spec.js +8 -0
  37. package/esm/models/HttpError.d.ts +5 -0
  38. package/esm/models/HttpError.js +8 -0
  39. package/esm/models/IProject.d.ts +2 -0
  40. package/esm/models/IProjectInfo.d.ts +14 -0
  41. package/esm/models/IProjectInfo.js +1 -0
  42. package/esm/models/index.d.ts +2 -0
  43. package/esm/models/index.js +2 -0
  44. package/esm/models/workflow/Workflow.d.ts +69 -11
  45. package/esm/node/RocosSDKNode.js +3 -2
  46. package/esm/services/BaseServiceAbstract.js +2 -9
  47. package/esm/services/ProjectService.d.ts +5 -9
  48. package/esm/services/ProjectService.js +5 -2
  49. package/esm/services/WorkflowService.d.ts +11 -16
  50. package/esm/services/WorkflowService.js +33 -16
  51. package/esm/services/WorkflowServiceNode.d.ts +4 -0
  52. package/esm/services/WorkflowServiceNode.js +8 -0
  53. package/package.json +1 -1
@@ -130,4 +130,6 @@ 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";
135
+ export declare const API_LINKED_PROJECT_URL = "https://{url}/linked-projects/{linkedProjectId}";
@@ -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_LINKED_PROJECT_URL = 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,6 @@ 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';
140
+ exports.API_LINKED_PROJECT_URL = 'https://{url}/linked-projects/{linkedProjectId}';
@@ -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
+ });
@@ -0,0 +1,5 @@
1
+ export declare class HttpError extends Error {
2
+ response: Response;
3
+ payload: string;
4
+ constructor(response: Response, payload: string);
5
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpError = void 0;
4
+ class HttpError extends Error {
5
+ constructor(response, payload) {
6
+ super(response.statusText);
7
+ this.response = response;
8
+ this.payload = payload;
9
+ this.name = 'HttpError';
10
+ }
11
+ }
12
+ exports.HttpError = HttpError;
@@ -1,4 +1,6 @@
1
1
  export interface IProject {
2
+ id: string;
2
3
  name: string;
4
+ linkedProjectId?: string;
3
5
  description: string;
4
6
  }
@@ -0,0 +1,14 @@
1
+ export interface IProjectInfo {
2
+ id: string;
3
+ name: string;
4
+ linkedProjectId?: string;
5
+ description: string;
6
+ userCount: number;
7
+ robotCount: number;
8
+ linkedProjectName?: string;
9
+ linkedProjectThumbnail?: string;
10
+ location?: {
11
+ lng: number;
12
+ lat: number;
13
+ };
14
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -34,6 +34,7 @@ export * from './maps/Map';
34
34
  export * from './projects/ProjectUser';
35
35
  export * from './CallsignStatus';
36
36
  export * from './ExportDataQuery';
37
+ export * from './HttpError';
37
38
  export * from './IBaseService';
38
39
  export * from './IConfigGroup';
39
40
  export * from './IDebugLevel';
@@ -45,6 +46,7 @@ export * from './IOperation';
45
46
  export * from './IPersonalAccessToken';
46
47
  export * from './IProject';
47
48
  export * from './IProjectApplication';
49
+ export * from './IProjectInfo';
48
50
  export * from './IRobot';
49
51
  export * from './IRobotConfig';
50
52
  export * from './IRobotPlugin';
@@ -50,6 +50,7 @@ __exportStar(require("./maps/Map"), exports);
50
50
  __exportStar(require("./projects/ProjectUser"), exports);
51
51
  __exportStar(require("./CallsignStatus"), exports);
52
52
  __exportStar(require("./ExportDataQuery"), exports);
53
+ __exportStar(require("./HttpError"), exports);
53
54
  __exportStar(require("./IBaseService"), exports);
54
55
  __exportStar(require("./IConfigGroup"), exports);
55
56
  __exportStar(require("./IDebugLevel"), exports);
@@ -61,6 +62,7 @@ __exportStar(require("./IOperation"), exports);
61
62
  __exportStar(require("./IPersonalAccessToken"), exports);
62
63
  __exportStar(require("./IProject"), exports);
63
64
  __exportStar(require("./IProjectApplication"), exports);
65
+ __exportStar(require("./IProjectInfo"), exports);
64
66
  __exportStar(require("./IRobot"), exports);
65
67
  __exportStar(require("./IRobotConfig"), exports);
66
68
  __exportStar(require("./IRobotPlugin"), exports);
@@ -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
- path: string;
9
- size: number;
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: string;
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 {};
@@ -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 services_1.WorkflowService(config);
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);
@@ -4,13 +4,6 @@ exports.BaseServiceAbstract = void 0;
4
4
  const models_1 = require("../models");
5
5
  const helpers_1 = require("../helpers");
6
6
  const RocosStore_1 = require("../store/RocosStore");
7
- class HttpError extends Error {
8
- constructor(response) {
9
- super(response.statusText);
10
- this.response = response;
11
- this.name = 'HttpError';
12
- }
13
- }
14
7
  class BaseServiceAbstract {
15
8
  constructor(config) {
16
9
  this.config = config;
@@ -57,7 +50,7 @@ class BaseServiceAbstract {
57
50
  const message = errorMessage;
58
51
  this.logger.error(message, e);
59
52
  let httpError = new models_1.RocosError(message);
60
- if (e instanceof HttpError) {
53
+ if (e instanceof models_1.HttpError) {
61
54
  httpError = this.getError(e);
62
55
  httpError.statusCode = e?.response?.status;
63
56
  }
@@ -71,7 +64,7 @@ class BaseServiceAbstract {
71
64
  if (!res.ok) {
72
65
  const payload = await res.text();
73
66
  this.logger.warn('Failed HTTP Response', { status: res.statusText, payload, response: res });
74
- throw new HttpError(res);
67
+ throw new models_1.HttpError(res, payload);
75
68
  }
76
69
  switch (responseType) {
77
70
  case 'raw':
@@ -1,10 +1,5 @@
1
- import { RocosError } from '../models/RocosError';
1
+ import { IBaseService, IOperation, IProject, IProjectInfo, IRocosSDKConfig, ProjectUser, RocosError } from '../models';
2
2
  import { BaseServiceAbstract } from './BaseServiceAbstract';
3
- import { IBaseService } from '../models/IBaseService';
4
- import { IOperation } from '../models/IOperation';
5
- import { IProject } from '../models/IProject';
6
- import { IRocosSDKConfig } from '../models/IRocosSDKConfig';
7
- import { ProjectUser } from '../models';
8
3
  export declare class ProjectService extends BaseServiceAbstract implements IBaseService {
9
4
  constructor(config: IRocosSDKConfig);
10
5
  protected getError(e: Error): RocosError;
@@ -18,7 +13,7 @@ export declare class ProjectService extends BaseServiceAbstract implements IBase
18
13
  /**
19
14
  * Get projects list by current account info
20
15
  */
21
- list(): Promise<any>;
16
+ list(): Promise<IProjectInfo[]>;
22
17
  /**
23
18
  * Update project information.
24
19
  *
@@ -31,7 +26,7 @@ export declare class ProjectService extends BaseServiceAbstract implements IBase
31
26
  *
32
27
  * @param projectId - Project Id
33
28
  */
34
- info(projectId: string): Promise<IProject>;
29
+ info(projectId: string): Promise<IProjectInfo>;
35
30
  /**
36
31
  * Delete project by account id and project id.
37
32
  *
@@ -44,7 +39,7 @@ export declare class ProjectService extends BaseServiceAbstract implements IBase
44
39
  *
45
40
  * @param accountId - Account Id
46
41
  */
47
- projectsUnderAccount(accountId: string): Promise<IProject[]>;
42
+ projectsUnderAccount(accountId: string): Promise<IProjectInfo[]>;
48
43
  /**
49
44
  * Create a project under a specified account
50
45
  *
@@ -107,4 +102,5 @@ export declare class ProjectService extends BaseServiceAbstract implements IBase
107
102
  * @returns Returns list of users for a given project
108
103
  */
109
104
  listUsers(projectId: string): Promise<ProjectUser[]>;
105
+ getProjectByLinkedProjectId(linkedProjectId: string): Promise<IProject>;
110
106
  }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ProjectService = void 0;
4
4
  const api_1 = require("../constants/api");
5
- const RocosError_1 = require("../models/RocosError");
5
+ const models_1 = require("../models");
6
6
  const BaseServiceAbstract_1 = require("./BaseServiceAbstract");
7
7
  const RocosLogger_1 = require("../logger/RocosLogger");
8
8
  const formatServiceUrl_1 = require("../helpers/formatServiceUrl");
@@ -12,7 +12,7 @@ class ProjectService extends BaseServiceAbstract_1.BaseServiceAbstract {
12
12
  this.logger = RocosLogger_1.RocosLogger.getInstance(`ProjectService(${this.config.url})`);
13
13
  }
14
14
  getError(e) {
15
- return new RocosError_1.RocosError(e, RocosError_1.errorCodes.PROJECT_SERVICE_ERROR);
15
+ return new models_1.RocosError(e, models_1.errorCodes.PROJECT_SERVICE_ERROR);
16
16
  }
17
17
  getStatus() {
18
18
  return true;
@@ -160,5 +160,8 @@ class ProjectService extends BaseServiceAbstract_1.BaseServiceAbstract {
160
160
  async listUsers(projectId) {
161
161
  return this.callGet((0, formatServiceUrl_1.formatServiceUrl)(api_1.API_PROJECT_USERS_URL, { url: this.config.url, projectId }, this.config.insecure), 'Failed to get project users list.');
162
162
  }
163
+ async getProjectByLinkedProjectId(linkedProjectId) {
164
+ return this.callGet((0, formatServiceUrl_1.formatServiceUrl)(api_1.API_LINKED_PROJECT_URL, { url: this.config.url, linkedProjectId }, this.config.insecure), `Failed to get project info for linked project ID: ${linkedProjectId}.`);
165
+ }
163
166
  }
164
167
  exports.ProjectService = ProjectService;
@@ -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,4 @@
1
+ import { WorkflowService } from './WorkflowService';
2
+ export declare class WorkflowServiceNode extends WorkflowService {
3
+ uploadAsset(projectId: string, workflowId: string, fileName: string, arrayBuffer: ArrayBuffer): Promise<void>;
4
+ }
@@ -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;
@@ -130,4 +130,6 @@ 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";
135
+ export declare const API_LINKED_PROJECT_URL = "https://{url}/linked-projects/{linkedProjectId}";
@@ -130,4 +130,6 @@ 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';
135
+ export const API_LINKED_PROJECT_URL = 'https://{url}/linked-projects/{linkedProjectId}';
@@ -0,0 +1 @@
1
+ export declare const getSha256Hex: (arrayBuffer: ArrayBuffer) => Promise<string>;
@@ -0,0 +1,5 @@
1
+ export const getSha256Hex = async (arrayBuffer) => {
2
+ const hashBuffer = await crypto.subtle.digest('SHA-256', arrayBuffer);
3
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
4
+ return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
5
+ };
@@ -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
+ });
@@ -0,0 +1,5 @@
1
+ export declare class HttpError extends Error {
2
+ response: Response;
3
+ payload: string;
4
+ constructor(response: Response, payload: string);
5
+ }
@@ -0,0 +1,8 @@
1
+ export class HttpError extends Error {
2
+ constructor(response, payload) {
3
+ super(response.statusText);
4
+ this.response = response;
5
+ this.payload = payload;
6
+ this.name = 'HttpError';
7
+ }
8
+ }
@@ -1,4 +1,6 @@
1
1
  export interface IProject {
2
+ id: string;
2
3
  name: string;
4
+ linkedProjectId?: string;
3
5
  description: string;
4
6
  }
@@ -0,0 +1,14 @@
1
+ export interface IProjectInfo {
2
+ id: string;
3
+ name: string;
4
+ linkedProjectId?: string;
5
+ description: string;
6
+ userCount: number;
7
+ robotCount: number;
8
+ linkedProjectName?: string;
9
+ linkedProjectThumbnail?: string;
10
+ location?: {
11
+ lng: number;
12
+ lat: number;
13
+ };
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -34,6 +34,7 @@ export * from './maps/Map';
34
34
  export * from './projects/ProjectUser';
35
35
  export * from './CallsignStatus';
36
36
  export * from './ExportDataQuery';
37
+ export * from './HttpError';
37
38
  export * from './IBaseService';
38
39
  export * from './IConfigGroup';
39
40
  export * from './IDebugLevel';
@@ -45,6 +46,7 @@ export * from './IOperation';
45
46
  export * from './IPersonalAccessToken';
46
47
  export * from './IProject';
47
48
  export * from './IProjectApplication';
49
+ export * from './IProjectInfo';
48
50
  export * from './IRobot';
49
51
  export * from './IRobotConfig';
50
52
  export * from './IRobotPlugin';
@@ -34,6 +34,7 @@ export * from './maps/Map';
34
34
  export * from './projects/ProjectUser';
35
35
  export * from './CallsignStatus';
36
36
  export * from './ExportDataQuery';
37
+ export * from './HttpError';
37
38
  export * from './IBaseService';
38
39
  export * from './IConfigGroup';
39
40
  export * from './IDebugLevel';
@@ -45,6 +46,7 @@ export * from './IOperation';
45
46
  export * from './IPersonalAccessToken';
46
47
  export * from './IProject';
47
48
  export * from './IProjectApplication';
49
+ export * from './IProjectInfo';
48
50
  export * from './IRobot';
49
51
  export * from './IRobotConfig';
50
52
  export * from './IRobotPlugin';
@@ -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
- path: string;
9
- size: number;
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: string;
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 {};
@@ -1,4 +1,4 @@
1
- import { AssetStorageService, AuthService, ConfigGroupService, DashboardService, EventService, FunctionService, IntegrationService, MapService, ProfileService, ProjectService, RobotService, ScheduleService, SpotProvisioningServiceNode, StreamService, UserService, WorkflowService, } from '../services';
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 WorkflowService(config);
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,13 +1,6 @@
1
- import { RocosError } from '../models';
1
+ import { RocosError, HttpError } from '../models';
2
2
  import { getURLSearchParams } from '../helpers';
3
3
  import { RocosStore } from '../store/RocosStore';
4
- class HttpError extends Error {
5
- constructor(response) {
6
- super(response.statusText);
7
- this.response = response;
8
- this.name = 'HttpError';
9
- }
10
- }
11
4
  export class BaseServiceAbstract {
12
5
  constructor(config) {
13
6
  this.config = config;
@@ -68,7 +61,7 @@ export class BaseServiceAbstract {
68
61
  if (!res.ok) {
69
62
  const payload = await res.text();
70
63
  this.logger.warn('Failed HTTP Response', { status: res.statusText, payload, response: res });
71
- throw new HttpError(res);
64
+ throw new HttpError(res, payload);
72
65
  }
73
66
  switch (responseType) {
74
67
  case 'raw':
@@ -1,10 +1,5 @@
1
- import { RocosError } from '../models/RocosError';
1
+ import { IBaseService, IOperation, IProject, IProjectInfo, IRocosSDKConfig, ProjectUser, RocosError } from '../models';
2
2
  import { BaseServiceAbstract } from './BaseServiceAbstract';
3
- import { IBaseService } from '../models/IBaseService';
4
- import { IOperation } from '../models/IOperation';
5
- import { IProject } from '../models/IProject';
6
- import { IRocosSDKConfig } from '../models/IRocosSDKConfig';
7
- import { ProjectUser } from '../models';
8
3
  export declare class ProjectService extends BaseServiceAbstract implements IBaseService {
9
4
  constructor(config: IRocosSDKConfig);
10
5
  protected getError(e: Error): RocosError;
@@ -18,7 +13,7 @@ export declare class ProjectService extends BaseServiceAbstract implements IBase
18
13
  /**
19
14
  * Get projects list by current account info
20
15
  */
21
- list(): Promise<any>;
16
+ list(): Promise<IProjectInfo[]>;
22
17
  /**
23
18
  * Update project information.
24
19
  *
@@ -31,7 +26,7 @@ export declare class ProjectService extends BaseServiceAbstract implements IBase
31
26
  *
32
27
  * @param projectId - Project Id
33
28
  */
34
- info(projectId: string): Promise<IProject>;
29
+ info(projectId: string): Promise<IProjectInfo>;
35
30
  /**
36
31
  * Delete project by account id and project id.
37
32
  *
@@ -44,7 +39,7 @@ export declare class ProjectService extends BaseServiceAbstract implements IBase
44
39
  *
45
40
  * @param accountId - Account Id
46
41
  */
47
- projectsUnderAccount(accountId: string): Promise<IProject[]>;
42
+ projectsUnderAccount(accountId: string): Promise<IProjectInfo[]>;
48
43
  /**
49
44
  * Create a project under a specified account
50
45
  *
@@ -107,4 +102,5 @@ export declare class ProjectService extends BaseServiceAbstract implements IBase
107
102
  * @returns Returns list of users for a given project
108
103
  */
109
104
  listUsers(projectId: string): Promise<ProjectUser[]>;
105
+ getProjectByLinkedProjectId(linkedProjectId: string): Promise<IProject>;
110
106
  }
@@ -1,5 +1,5 @@
1
- import { API_ACCOUNT_PROJECT_ID_URL, API_ACCOUNT_PROJECT_URL, API_PROJECT_ID_URL, API_PROJECT_OPERATION_ID_URL, API_PROJECT_OPERATION_URL, API_PROJECT_URL, API_PROJECT_USERS_URL, API_TEMPLATE_PROVISION_ID_URL, API_TEMPLATE_PROVISION_URL, } from '../constants/api';
2
- import { RocosError, errorCodes } from '../models/RocosError';
1
+ import { API_ACCOUNT_PROJECT_ID_URL, API_ACCOUNT_PROJECT_URL, API_LINKED_PROJECT_URL, API_PROJECT_ID_URL, API_PROJECT_OPERATION_ID_URL, API_PROJECT_OPERATION_URL, API_PROJECT_URL, API_PROJECT_USERS_URL, API_TEMPLATE_PROVISION_ID_URL, API_TEMPLATE_PROVISION_URL, } from '../constants/api';
2
+ import { errorCodes, RocosError, } from '../models';
3
3
  import { BaseServiceAbstract } from './BaseServiceAbstract';
4
4
  import { RocosLogger } from '../logger/RocosLogger';
5
5
  import { formatServiceUrl } from '../helpers/formatServiceUrl';
@@ -157,4 +157,7 @@ export class ProjectService extends BaseServiceAbstract {
157
157
  async listUsers(projectId) {
158
158
  return this.callGet(formatServiceUrl(API_PROJECT_USERS_URL, { url: this.config.url, projectId }, this.config.insecure), 'Failed to get project users list.');
159
159
  }
160
+ async getProjectByLinkedProjectId(linkedProjectId) {
161
+ return this.callGet(formatServiceUrl(API_LINKED_PROJECT_URL, { url: this.config.url, linkedProjectId }, this.config.insecure), `Failed to get project info for linked project ID: ${linkedProjectId}.`);
162
+ }
160
163
  }
@@ -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,4 @@
1
+ import { WorkflowService } from './WorkflowService';
2
+ export declare class WorkflowServiceNode extends WorkflowService {
3
+ uploadAsset(projectId: string, workflowId: string, fileName: string, arrayBuffer: ArrayBuffer): Promise<void>;
4
+ }
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dronedeploy/rocos-js-sdk",
3
- "version": "3.0.1-alpha.6",
3
+ "version": "3.0.1-alpha.8",
4
4
  "description": "Javascript SDK for rocos",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",