Skip to content

Commit da1850b

Browse files
Support for new recipe management (#4)
Started supporting new recipe management which includes creating starting recipe blueprint and installing initial domain mapping file on snap-in activation. Added example of external domain metadata file and changes in demo extractor.
1 parent b11724c commit da1850b

12 files changed

+182
-153
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Typescript ADaaS Library (@devrev/ts-adaas) provides:
88

99
## Release Notes
1010

11+
#### v0.0.3
12+
13+
- Support for new recipe management
14+
1115
#### v0.0.2
1216

1317
- Support for the State API

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devrev/ts-adaas",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"description": "Typescript library containing the ADaaS(AirDrop as a Service) control protocol.",
55
"type": "commonjs",
66
"main": "./dist/src/index.js",
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import axios from 'axios';
2+
import { AirdropEvent } from '../types/extraction';
3+
import { InitialDomainMapping } from '../types/common';
4+
5+
export async function installInitialDomainMapping(
6+
event: AirdropEvent,
7+
initialDomainMappingJson: InitialDomainMapping
8+
) {
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+
13+
if (!initialDomainMappingJson) {
14+
console.warn('No initial domain mapping found');
15+
return;
16+
}
17+
18+
const snapInVersionResponse = await axios.get(
19+
devrevEndpoint + '/internal/snap-in-versions.get',
20+
{
21+
headers: {
22+
Authorization: devrevToken,
23+
},
24+
params: {
25+
id: snapInVersionId,
26+
},
27+
}
28+
);
29+
30+
const importSlug = snapInVersionResponse.data.snap_in_version.imports[0].slug;
31+
const snapInSlug = snapInVersionResponse.data.snap_in_version.slug;
32+
const startingRecipeBlueprint =
33+
initialDomainMappingJson?.starting_recipe_blueprint;
34+
35+
let recipeBlueprintId;
36+
if (
37+
startingRecipeBlueprint &&
38+
Object.keys(startingRecipeBlueprint).length !== 0
39+
) {
40+
try {
41+
const recipeBlueprintResponse = await axios.post(
42+
`${devrevEndpoint}/internal/airdrop.recipe.blueprints.create`,
43+
{
44+
...startingRecipeBlueprint,
45+
},
46+
{
47+
headers: {
48+
Authorization: devrevToken,
49+
},
50+
}
51+
);
52+
53+
recipeBlueprintId = recipeBlueprintResponse.data.recipe_blueprint.id;
54+
55+
console.log(
56+
'Successfully created recipe blueprint with id: ' + recipeBlueprintId
57+
);
58+
} catch (error) {
59+
console.error('Error while creating recipe blueprint', error);
60+
}
61+
}
62+
63+
try {
64+
// 2. Install the initial domain mappings
65+
const additionalMappings =
66+
initialDomainMappingJson.additional_mappings || {};
67+
const initialDomainMappingInstallResponse = await axios.post(
68+
`${devrevEndpoint}/internal/airdrop.recipe.initial-domain-mappings.install`,
69+
{
70+
external_system_type: 'ADaaS',
71+
import_slug: importSlug,
72+
snap_in_slug: snapInSlug,
73+
...(recipeBlueprintId && {
74+
starting_recipe_blueprint: recipeBlueprintId,
75+
}),
76+
...additionalMappings,
77+
},
78+
{
79+
headers: {
80+
Authorization: devrevToken,
81+
},
82+
}
83+
);
84+
85+
console.log(
86+
'Successfully installed initial domain mapping',
87+
initialDomainMappingInstallResponse.data
88+
);
89+
} catch (error) {
90+
console.error('Error while installing initial domain mapping', error);
91+
return;
92+
}
93+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

src/demo-extractor/index.ts

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { Adapter } from '../adapter';
99
import { Uploader } from '../uploader';
1010

11-
import extractorInitialDomainMapping from './initial_domain_mapping.json';
11+
import externalDomainMetadata from './external_domain_metadata.json';
1212

1313
type ExtractorState = object;
1414

@@ -48,21 +48,10 @@ export class DemoExtractor {
4848
}
4949

5050
case EventType.ExtractionMetadataStart: {
51-
const metadata = [
52-
{
53-
item: 'contacts',
54-
fields: ['id', 'name', 'lastName'],
55-
},
56-
{
57-
item: 'users',
58-
fields: ['id', 'name', 'lastName'],
59-
},
60-
];
61-
6251
const { artifact, error } = await this.uploader.upload(
63-
'loopback_metadata_1.jsonl',
64-
'metadata',
65-
metadata
52+
'metadata_1.jsonl',
53+
'external_domain_metadata',
54+
externalDomainMetadata
6655
);
6756

6857
if (error || !artifact) {
@@ -72,23 +61,8 @@ export class DemoExtractor {
7261
return;
7362
}
7463

75-
const { artifact: recipe, error: recipeError } =
76-
await this.uploader.upload(
77-
'recipe.json',
78-
'initial_domain_mapping',
79-
extractorInitialDomainMapping
80-
);
81-
82-
if (recipeError || !recipe) {
83-
await this.adapter.emit(ExtractorEventType.ExtractionMetadataError, {
84-
error: recipeError,
85-
});
86-
return;
87-
}
88-
8964
await this.adapter.emit(ExtractorEventType.ExtractionMetadataDone, {
90-
progress: 50,
91-
artifacts: [artifact, recipe],
65+
artifacts: [artifact],
9266
});
9367

9468
break;
@@ -97,19 +71,27 @@ export class DemoExtractor {
9771
case EventType.ExtractionDataStart: {
9872
const contacts = [
9973
{
100-
id: 1,
101-
name: 'John',
102-
lastName: 'Doe',
74+
id: 'contact-1',
75+
created_date: '1999-12-25T01:00:03+01:00',
76+
modified_date: '1999-12-25T01:00:03+01:00',
77+
data: {
78+
79+
name: 'John Smith',
80+
},
10381
},
10482
{
105-
id: 2,
106-
name: 'Jane',
107-
lastName: 'Doe',
83+
id: 'contact-2',
84+
created_date: '1999-12-27T15:31:34+01:00',
85+
modified_date: '2002-04-09T01:55:31+02:00',
86+
data: {
87+
88+
name: 'Jane Smith',
89+
},
10890
},
10991
];
11092

11193
const { artifact, error } = await this.uploader.upload(
112-
'loopback_contacts_1.json',
94+
'contacts_1.json',
11395
'contacts',
11496
contacts
11597
);
@@ -133,19 +115,27 @@ export class DemoExtractor {
133115
case EventType.ExtractionDataContinue: {
134116
const users = [
135117
{
136-
id: 1,
137-
name: 'John',
138-
lastName: 'Phd',
118+
id: 'user-1',
119+
created_date: '1999-12-25T01:00:03+01:00',
120+
modified_date: '1999-12-25T01:00:03+01:00',
121+
data: {
122+
123+
name: 'John Doe',
124+
},
139125
},
140126
{
141-
id: 2,
142-
name: 'Jane',
143-
lastName: 'Phd',
127+
id: 'user-2',
128+
created_date: '1999-12-27T15:31:34+01:00',
129+
modified_date: '2002-04-09T01:55:31+02:00',
130+
data: {
131+
132+
name: 'Jane Doe',
133+
},
144134
},
145135
];
146136

147137
const { artifact, error } = await this.uploader.upload(
148-
'loopback_users_1.json',
138+
'users_1.json',
149139
'users',
150140
users
151141
);

src/demo-extractor/initial_domain_mapping.json

Lines changed: 0 additions & 107 deletions
This file was deleted.

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ export * from './demo-extractor';
33
export * from './uploader';
44
export * from './types';
55
export * from './http';
6+
7+
export * from './common/install-initial-domain-mapping';

0 commit comments

Comments
 (0)