@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 +4 -0
- package/dist/src/common/install-initial-domain-mapping.d.ts +3 -0
- package/dist/src/common/install-initial-domain-mapping.js +60 -0
- package/dist/src/demo-extractor/external_domain_metadata.json +38 -0
- package/dist/src/demo-extractor/index.js +33 -35
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/types/common.d.ts +4 -0
- package/dist/src/types/extraction.d.ts +1 -0
- package/dist/tests/adapter.test.js +1 -0
- package/dist/tests/demo-extractor.test.js +1 -0
- package/dist/tests/state.test.js +1 -0
- package/package.json +1 -1
- package/dist/src/demo-extractor/initial_domain_mapping.json +0 -107
package/README.md
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
67
|
-
|
|
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
|
-
|
|
72
|
-
|
|
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('
|
|
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
|
-
|
|
93
|
-
|
|
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
|
-
|
|
98
|
-
|
|
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('
|
|
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,
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
package/dist/tests/state.test.js
CHANGED
package/package.json
CHANGED
|
@@ -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
|
-
}
|