@devrev/ts-adaas 0.0.2 → 0.0.3

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/README.md CHANGED
@@ -8,6 +8,10 @@ Typescript ADaaS Library (@devrev/ts-adaas) provides:
8
8
 
9
9
  ## Release Notes
10
10
 
11
+ #### v0.0.3
12
+
13
+ - Support for new recipe management
14
+
11
15
  #### v0.0.2
12
16
 
13
17
  - Support for the State API
@@ -0,0 +1,3 @@
1
+ import { AirdropEvent } from '../types/extraction';
2
+ import { InitialDomainMapping } from '../types/common';
3
+ export declare function installInitialDomainMapping(event: AirdropEvent, initialDomainMappingJson: InitialDomainMapping): Promise<void>;
@@ -0,0 +1,60 @@
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.installInitialDomainMapping = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ async function installInitialDomainMapping(event, initialDomainMappingJson) {
9
+ const devrevEndpoint = event.execution_metadata.devrev_endpoint;
10
+ const devrevToken = event.context.secrets.service_account_token;
11
+ const snapInVersionId = event.context.snap_in_version_id;
12
+ if (!initialDomainMappingJson) {
13
+ console.warn('No initial domain mapping found');
14
+ return;
15
+ }
16
+ const snapInVersionResponse = await axios_1.default.get(devrevEndpoint + '/internal/snap-in-versions.get', {
17
+ headers: {
18
+ Authorization: devrevToken,
19
+ },
20
+ params: {
21
+ id: snapInVersionId,
22
+ },
23
+ });
24
+ const importSlug = snapInVersionResponse.data.snap_in_version.imports[0].slug;
25
+ const snapInSlug = snapInVersionResponse.data.snap_in_version.slug;
26
+ const startingRecipeBlueprint = initialDomainMappingJson === null || initialDomainMappingJson === void 0 ? void 0 : initialDomainMappingJson.starting_recipe_blueprint;
27
+ let recipeBlueprintId;
28
+ if (startingRecipeBlueprint &&
29
+ Object.keys(startingRecipeBlueprint).length !== 0) {
30
+ try {
31
+ const recipeBlueprintResponse = await axios_1.default.post(`${devrevEndpoint}/internal/airdrop.recipe.blueprints.create`, Object.assign({}, startingRecipeBlueprint), {
32
+ headers: {
33
+ Authorization: devrevToken,
34
+ },
35
+ });
36
+ recipeBlueprintId = recipeBlueprintResponse.data.recipe_blueprint.id;
37
+ console.log('Successfully created recipe blueprint with id: ' + recipeBlueprintId);
38
+ }
39
+ catch (error) {
40
+ console.error('Error while creating recipe blueprint', error);
41
+ }
42
+ }
43
+ try {
44
+ // 2. Install the initial domain mappings
45
+ const additionalMappings = initialDomainMappingJson.additional_mappings || {};
46
+ const initialDomainMappingInstallResponse = await axios_1.default.post(`${devrevEndpoint}/internal/airdrop.recipe.initial-domain-mappings.install`, Object.assign(Object.assign({ external_system_type: 'ADaaS', import_slug: importSlug, snap_in_slug: snapInSlug }, (recipeBlueprintId && {
47
+ starting_recipe_blueprint: recipeBlueprintId,
48
+ })), additionalMappings), {
49
+ headers: {
50
+ Authorization: devrevToken,
51
+ },
52
+ });
53
+ console.log('Successfully installed initial domain mapping', initialDomainMappingInstallResponse.data);
54
+ }
55
+ catch (error) {
56
+ console.error('Error while installing initial domain mapping', error);
57
+ return;
58
+ }
59
+ }
60
+ exports.installInitialDomainMapping = installInitialDomainMapping;
@@ -0,0 +1,38 @@
1
+ {
2
+ "record_types": {
3
+ "users": {
4
+ "fields": {
5
+ "name": {
6
+ "is_required": true,
7
+ "type": "text",
8
+ "name": "Name",
9
+ "text": {
10
+ "min_length": 1
11
+ }
12
+ },
13
+ "email": {
14
+ "type": "text",
15
+ "name": "Email",
16
+ "is_required": true
17
+ }
18
+ }
19
+ },
20
+ "contacts": {
21
+ "fields": {
22
+ "name": {
23
+ "is_required": true,
24
+ "type": "text",
25
+ "name": "Name",
26
+ "text": {
27
+ "min_length": 1
28
+ }
29
+ },
30
+ "email": {
31
+ "type": "text",
32
+ "name": "Email",
33
+ "is_required": true
34
+ }
35
+ }
36
+ }
37
+ }
38
+ }
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.DemoExtractor = void 0;
7
7
  const types_1 = require("../types");
8
8
  const uploader_1 = require("../uploader");
9
- const initial_domain_mapping_json_1 = __importDefault(require("./initial_domain_mapping.json"));
9
+ const external_domain_metadata_json_1 = __importDefault(require("./external_domain_metadata.json"));
10
10
  class DemoExtractor {
11
11
  constructor(event, adapter) {
12
12
  this.event = event;
@@ -29,50 +29,40 @@ class DemoExtractor {
29
29
  break;
30
30
  }
31
31
  case types_1.EventType.ExtractionMetadataStart: {
32
- const metadata = [
33
- {
34
- item: 'contacts',
35
- fields: ['id', 'name', 'lastName'],
36
- },
37
- {
38
- item: 'users',
39
- fields: ['id', 'name', 'lastName'],
40
- },
41
- ];
42
- const { artifact, error } = await this.uploader.upload('loopback_metadata_1.jsonl', 'metadata', metadata);
32
+ const { artifact, error } = await this.uploader.upload('metadata_1.jsonl', 'external_domain_metadata', external_domain_metadata_json_1.default);
43
33
  if (error || !artifact) {
44
34
  await this.adapter.emit(types_1.ExtractorEventType.ExtractionMetadataError, {
45
35
  error,
46
36
  });
47
37
  return;
48
38
  }
49
- const { artifact: recipe, error: recipeError } = await this.uploader.upload('recipe.json', 'initial_domain_mapping', initial_domain_mapping_json_1.default);
50
- if (recipeError || !recipe) {
51
- await this.adapter.emit(types_1.ExtractorEventType.ExtractionMetadataError, {
52
- error: recipeError,
53
- });
54
- return;
55
- }
56
39
  await this.adapter.emit(types_1.ExtractorEventType.ExtractionMetadataDone, {
57
- progress: 50,
58
- artifacts: [artifact, recipe],
40
+ artifacts: [artifact],
59
41
  });
60
42
  break;
61
43
  }
62
44
  case types_1.EventType.ExtractionDataStart: {
63
45
  const contacts = [
64
46
  {
65
- id: 1,
66
- name: 'John',
67
- lastName: 'Doe',
47
+ id: 'contact-1',
48
+ created_date: '1999-12-25T01:00:03+01:00',
49
+ modified_date: '1999-12-25T01:00:03+01:00',
50
+ data: {
51
+ email: 'johnsmith@test.com',
52
+ name: 'John Smith',
53
+ },
68
54
  },
69
55
  {
70
- id: 2,
71
- name: 'Jane',
72
- lastName: 'Doe',
56
+ id: 'contact-2',
57
+ created_date: '1999-12-27T15:31:34+01:00',
58
+ modified_date: '2002-04-09T01:55:31+02:00',
59
+ data: {
60
+ email: 'janesmith@test.com',
61
+ name: 'Jane Smith',
62
+ },
73
63
  },
74
64
  ];
75
- const { artifact, error } = await this.uploader.upload('loopback_contacts_1.json', 'contacts', contacts);
65
+ const { artifact, error } = await this.uploader.upload('contacts_1.json', 'contacts', contacts);
76
66
  if (error || !artifact) {
77
67
  await this.adapter.emit(types_1.ExtractorEventType.ExtractionDataError, {
78
68
  error,
@@ -88,17 +78,25 @@ class DemoExtractor {
88
78
  case types_1.EventType.ExtractionDataContinue: {
89
79
  const users = [
90
80
  {
91
- id: 1,
92
- name: 'John',
93
- lastName: 'Phd',
81
+ id: 'user-1',
82
+ created_date: '1999-12-25T01:00:03+01:00',
83
+ modified_date: '1999-12-25T01:00:03+01:00',
84
+ data: {
85
+ email: 'johndoe@test.com',
86
+ name: 'John Doe',
87
+ },
94
88
  },
95
89
  {
96
- id: 2,
97
- name: 'Jane',
98
- lastName: 'Phd',
90
+ id: 'user-2',
91
+ created_date: '1999-12-27T15:31:34+01:00',
92
+ modified_date: '2002-04-09T01:55:31+02:00',
93
+ data: {
94
+ email: 'janedoe@test.com',
95
+ name: 'Jane Doe',
96
+ },
99
97
  },
100
98
  ];
101
- const { artifact, error } = await this.uploader.upload('loopback_users_1.json', 'users', users);
99
+ const { artifact, error } = await this.uploader.upload('users_1.json', 'users', users);
102
100
  if (error || !artifact) {
103
101
  await this.adapter.emit(types_1.ExtractorEventType.ExtractionDataError, {
104
102
  error,
@@ -3,3 +3,4 @@ export * from './demo-extractor';
3
3
  export * from './uploader';
4
4
  export * from './types';
5
5
  export * from './http';
6
+ export * from './common/install-initial-domain-mapping';
package/dist/src/index.js CHANGED
@@ -19,3 +19,4 @@ __exportStar(require("./demo-extractor"), exports);
19
19
  __exportStar(require("./uploader"), exports);
20
20
  __exportStar(require("./types"), exports);
21
21
  __exportStar(require("./http"), exports);
22
+ __exportStar(require("./common/install-initial-domain-mapping"), exports);
@@ -31,3 +31,7 @@ export interface UploadResponse {
31
31
  artifact?: Artifact;
32
32
  error?: ErrorRecord;
33
33
  }
34
+ export interface InitialDomainMapping {
35
+ starting_recipe_blueprint?: object;
36
+ additional_mappings?: object;
37
+ }
@@ -90,6 +90,7 @@ export interface AirdropEvent {
90
90
  secrets: {
91
91
  service_account_token: string;
92
92
  };
93
+ snap_in_version_id: string;
93
94
  };
94
95
  payload: AirdropMessage;
95
96
  execution_metadata: {
@@ -24,6 +24,7 @@ describe('Adapter', () => {
24
24
  secrets: {
25
25
  service_account_token: 'service_account_token',
26
26
  },
27
+ snap_in_version_id: 'snap_in_version_id',
27
28
  },
28
29
  payload: {
29
30
  connection_data: {
@@ -11,6 +11,7 @@ const mockEvent = {
11
11
  secrets: {
12
12
  service_account_token: 'service_account_token',
13
13
  },
14
+ snap_in_version_id: 'snap_in_version_id',
14
15
  },
15
16
  payload: {
16
17
  connection_data: {
@@ -18,6 +18,7 @@ describe('AdapterState', () => {
18
18
  secrets: {
19
19
  service_account_token: 'service_account_token',
20
20
  },
21
+ snap_in_version_id: 'snap_in_version_id',
21
22
  },
22
23
  payload: {
23
24
  connection_data: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devrev/ts-adaas",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Typescript library containing the ADaaS(AirDrop as a Service) control protocol.",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/src/index.js",
@@ -1,107 +0,0 @@
1
- {
2
- "initial_object_mappings": [
3
- {
4
- "external_type": "contacts",
5
- "possible_targets": {
6
- "rev_user": {
7
- "initial_field_mappings": [
8
- {
9
- "destination_field": {
10
- "id": "id",
11
- "is_required": true
12
- },
13
- "selected_resolutions": ["id"],
14
- "resolutions": {
15
- "id": {
16
- "source_field_description": {
17
- "id": "id",
18
- "is_required": true
19
- }
20
- }
21
- },
22
- "is_finished": true
23
- },
24
- {
25
- "destination_field": {
26
- "id": "display_name",
27
- "is_required": true
28
- },
29
- "selected_resolutions": ["name"],
30
- "resolutions": {
31
- "name": {
32
- "source_field_description": {
33
- "id": "name",
34
- "is_required": true
35
- }
36
- }
37
- },
38
- "is_finished": true
39
- }
40
- ]
41
- }
42
- },
43
- "default_target": "rev_user",
44
- "allow_item_type_decisions": true
45
- },
46
- {
47
- "external_type": "users",
48
- "possible_targets": {
49
- "dev_user": {
50
- "initial_field_mappings": [
51
- {
52
- "destination_field": {
53
- "id": "id",
54
- "is_required": true
55
- },
56
- "selected_resolutions": ["id"],
57
- "resolutions": {
58
- "id": {
59
- "source_field_description": {
60
- "id": "id",
61
- "is_required": true
62
- }
63
- }
64
- },
65
- "is_finished": true
66
- },
67
- {
68
- "destination_field": {
69
- "id": "display_name",
70
- "is_required": true
71
- },
72
- "selected_resolutions": ["name"],
73
- "resolutions": {
74
- "name": {
75
- "source_field_description": {
76
- "id": "name",
77
- "is_required": true
78
- }
79
- }
80
- },
81
- "is_finished": true
82
- }
83
- ]
84
- }
85
- },
86
- "default_target": "dev_user",
87
- "allow_item_type_decisions": true
88
- },
89
- {
90
- "external_type": "tickets",
91
- "possible_targets": {
92
- "work.ticket": {}
93
- },
94
- "default_target": "work.ticket",
95
- "allow_item_type_decisions": true
96
- },
97
- {
98
- "external_type": "conversations",
99
- "possible_targets": {
100
- "comment": {}
101
- },
102
- "default_target": "comment",
103
- "allow_item_type_decisions": true
104
- }
105
- ],
106
- "external_system_short_name": "Freshdesk"
107
- }