-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
b11724c
commit da1850b
Showing
12 changed files
with
182 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import axios from 'axios'; | ||
import { AirdropEvent } from '../types/extraction'; | ||
import { InitialDomainMapping } from '../types/common'; | ||
|
||
export async function installInitialDomainMapping( | ||
event: AirdropEvent, | ||
initialDomainMappingJson: InitialDomainMapping | ||
) { | ||
const devrevEndpoint = event.execution_metadata.devrev_endpoint; | ||
const devrevToken = event.context.secrets.service_account_token; | ||
const snapInVersionId = event.context.snap_in_version_id; | ||
|
||
if (!initialDomainMappingJson) { | ||
console.warn('No initial domain mapping found'); | ||
return; | ||
} | ||
|
||
const snapInVersionResponse = await axios.get( | ||
devrevEndpoint + '/internal/snap-in-versions.get', | ||
{ | ||
headers: { | ||
Authorization: devrevToken, | ||
}, | ||
params: { | ||
id: snapInVersionId, | ||
}, | ||
} | ||
); | ||
|
||
const importSlug = snapInVersionResponse.data.snap_in_version.imports[0].slug; | ||
const snapInSlug = snapInVersionResponse.data.snap_in_version.slug; | ||
const startingRecipeBlueprint = | ||
initialDomainMappingJson?.starting_recipe_blueprint; | ||
|
||
let recipeBlueprintId; | ||
if ( | ||
startingRecipeBlueprint && | ||
Object.keys(startingRecipeBlueprint).length !== 0 | ||
) { | ||
try { | ||
const recipeBlueprintResponse = await axios.post( | ||
`${devrevEndpoint}/internal/airdrop.recipe.blueprints.create`, | ||
{ | ||
...startingRecipeBlueprint, | ||
}, | ||
{ | ||
headers: { | ||
Authorization: devrevToken, | ||
}, | ||
} | ||
); | ||
|
||
recipeBlueprintId = recipeBlueprintResponse.data.recipe_blueprint.id; | ||
|
||
console.log( | ||
'Successfully created recipe blueprint with id: ' + recipeBlueprintId | ||
); | ||
} catch (error) { | ||
console.error('Error while creating recipe blueprint', error); | ||
} | ||
} | ||
|
||
try { | ||
// 2. Install the initial domain mappings | ||
const additionalMappings = | ||
initialDomainMappingJson.additional_mappings || {}; | ||
const initialDomainMappingInstallResponse = await axios.post( | ||
`${devrevEndpoint}/internal/airdrop.recipe.initial-domain-mappings.install`, | ||
{ | ||
external_system_type: 'ADaaS', | ||
import_slug: importSlug, | ||
snap_in_slug: snapInSlug, | ||
...(recipeBlueprintId && { | ||
starting_recipe_blueprint: recipeBlueprintId, | ||
}), | ||
...additionalMappings, | ||
}, | ||
{ | ||
headers: { | ||
Authorization: devrevToken, | ||
}, | ||
} | ||
); | ||
|
||
console.log( | ||
'Successfully installed initial domain mapping', | ||
initialDomainMappingInstallResponse.data | ||
); | ||
} catch (error) { | ||
console.error('Error while installing initial domain mapping', error); | ||
return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"record_types": { | ||
"users": { | ||
"fields": { | ||
"name": { | ||
"is_required": true, | ||
"type": "text", | ||
"name": "Name", | ||
"text": { | ||
"min_length": 1 | ||
} | ||
}, | ||
"email": { | ||
"type": "text", | ||
"name": "Email", | ||
"is_required": true | ||
} | ||
} | ||
}, | ||
"contacts": { | ||
"fields": { | ||
"name": { | ||
"is_required": true, | ||
"type": "text", | ||
"name": "Name", | ||
"text": { | ||
"min_length": 1 | ||
} | ||
}, | ||
"email": { | ||
"type": "text", | ||
"name": "Email", | ||
"is_required": true | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.