From 1bb8757cdd6f3a0705b6bae2171058636a4aaee3 Mon Sep 17 00:00:00 2001 From: radovan-jorgic <147607814+radovan-jorgic@users.noreply.github.com> Date: Tue, 17 Sep 2024 09:38:54 +0200 Subject: [PATCH] Support for new recipe management and example of initial domain mapping (#7) Added support for new recipe management which includes creation of recipe blueprint and installing initial domain mapping file. --- code/package-lock.json | 14 +-- code/package.json | 2 +- code/src/function-factory.ts | 4 +- .../extraction/initial_domain_mapping.json | 107 ++++++++++++++++++ .../install_initial_domain_mapping/index.ts | 16 +++ manifest.yaml | 6 + 6 files changed, 140 insertions(+), 9 deletions(-) create mode 100644 code/src/functions/extraction/initial_domain_mapping.json create mode 100644 code/src/functions/install_initial_domain_mapping/index.ts diff --git a/code/package-lock.json b/code/package-lock.json index 8ba43f2..9e73850 100644 --- a/code/package-lock.json +++ b/code/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "@devrev/ts-adaas": "0.0.2", + "@devrev/ts-adaas": "0.0.3", "axios": "^1.5.1", "dotenv": "^16.0.3", "js-jsonl": "^1.1.1", @@ -1832,9 +1832,9 @@ } }, "node_modules/@devrev/ts-adaas": { - "version": "0.0.2", - "resolved": "https://registry.npmjs.org/@devrev/ts-adaas/-/ts-adaas-0.0.2.tgz", - "integrity": "sha512-qBIibkgTVZoes9ROZU8YEvpBxWMxv4ScVNB63Dwu820aC5hdzHn7YbUPBJFPqTwDxvqK8tgIvuCtIkJbGZwsJw==", + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/@devrev/ts-adaas/-/ts-adaas-0.0.3.tgz", + "integrity": "sha512-1AKG7K03goRTdovpuhOQsmU8TcLSYqdXonHKbdqm93quSKzmTBaeKJpXG4G+1Rtqm/b8OL2aJILLSffsqUxDzg==", "dependencies": { "@devrev/typescript-sdk": "^1.1.27", "axios": "^1.5.1", @@ -12040,9 +12040,9 @@ } }, "@devrev/ts-adaas": { - "version": "0.0.2", - "resolved": "https://registry.npmjs.org/@devrev/ts-adaas/-/ts-adaas-0.0.2.tgz", - "integrity": "sha512-qBIibkgTVZoes9ROZU8YEvpBxWMxv4ScVNB63Dwu820aC5hdzHn7YbUPBJFPqTwDxvqK8tgIvuCtIkJbGZwsJw==", + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/@devrev/ts-adaas/-/ts-adaas-0.0.3.tgz", + "integrity": "sha512-1AKG7K03goRTdovpuhOQsmU8TcLSYqdXonHKbdqm93quSKzmTBaeKJpXG4G+1Rtqm/b8OL2aJILLSffsqUxDzg==", "requires": { "@devrev/typescript-sdk": "^1.1.27", "axios": "^1.5.1", diff --git a/code/package.json b/code/package.json index 45b9025..b2c75ab 100644 --- a/code/package.json +++ b/code/package.json @@ -55,7 +55,7 @@ "yargs": "^17.6.2" }, "dependencies": { - "@devrev/ts-adaas": "0.0.2", + "@devrev/ts-adaas": "0.0.3", "axios": "^1.5.1", "dotenv": "^16.0.3", "js-jsonl": "^1.1.1", diff --git a/code/src/function-factory.ts b/code/src/function-factory.ts index 8665cce..48e0974 100644 --- a/code/src/function-factory.ts +++ b/code/src/function-factory.ts @@ -1,7 +1,9 @@ -import extraction from './functions/extraction/index'; +import extraction from './functions/extraction'; +import install_initial_domain_mapping from './functions/install_initial_domain_mapping'; export const functionFactory = { extraction, + install_initial_domain_mapping, } as const; export type FunctionFactoryType = keyof typeof functionFactory; diff --git a/code/src/functions/extraction/initial_domain_mapping.json b/code/src/functions/extraction/initial_domain_mapping.json new file mode 100644 index 0000000..8edce76 --- /dev/null +++ b/code/src/functions/extraction/initial_domain_mapping.json @@ -0,0 +1,107 @@ +{ + "starting_recipe_blueprint": { + "external_record_types": { + "contacts": { + "forward": true, + "reverse": false, + "shard": { + "constructed_custom_fields": {}, + "devrev_leaf_type": { + "object_type": "revu" + }, + "shard": "create_shard", + "stock_field_mappings": { + "display_name": { + "forward": true, + "primary_external_field": "name", + "reverse": false, + "transformation_method": { + "transformation_method": "use_directly" + } + }, + "email": { + "forward": true, + "primary_external_field": "email", + "reverse": false, + "transformation_method": { + "transformation_method": "use_directly" + } + }, + "full_name": { + "forward": true, + "primary_external_field": "name", + "reverse": false, + "transformation_method": { + "transformation_method": "use_directly" + } + }, + "state": { + "forward": true, + "reverse": false, + "transformation_method": { + "enum": "UNASSIGNED", + "transformation_method": "use_fixed_value", + "value": "enum_value" + } + }, + "user_type": { + "forward": true, + "reverse": false, + "transformation_method": { + "enum": "IDENTIFIED", + "transformation_method": "use_fixed_value", + "value": "enum_value" + } + } + } + } + }, + "users": { + "forward": true, + "reverse": false, + "shard": { + "constructed_custom_fields": {}, + "devrev_leaf_type": { + "object_type": "devu" + }, + "shard": "create_shard", + "stock_field_mappings": { + "display_name": { + "forward": true, + "primary_external_field": "name", + "reverse": false, + "transformation_method": { + "transformation_method": "use_directly" + } + }, + "email": { + "forward": true, + "primary_external_field": "email", + "reverse": false, + "transformation_method": { + "transformation_method": "use_directly" + } + }, + "full_name": { + "forward": true, + "primary_external_field": "name", + "reverse": false, + "transformation_method": { + "transformation_method": "use_directly" + } + }, + "state": { + "forward": true, + "reverse": false, + "transformation_method": { + "enum": "UNASSIGNED", + "transformation_method": "use_fixed_value", + "value": "enum_value" + } + } + } + } + } + } + } +} diff --git a/code/src/functions/install_initial_domain_mapping/index.ts b/code/src/functions/install_initial_domain_mapping/index.ts new file mode 100644 index 0000000..1911365 --- /dev/null +++ b/code/src/functions/install_initial_domain_mapping/index.ts @@ -0,0 +1,16 @@ +import { AirdropEvent, installInitialDomainMapping } from '@devrev/ts-adaas'; + +import initialDomainMapping from '../extraction/initial_domain_mapping.json'; + +const run = async (events: AirdropEvent[]) => { + for (const event of events) { + try { + await installInitialDomainMapping(event, initialDomainMapping); + } catch (error) { + console.error('Failed to install initial domain mappings', error); + throw error; + } + } +}; + +export default run; diff --git a/manifest.yaml b/manifest.yaml index 5308f1f..3c962ee 100644 --- a/manifest.yaml +++ b/manifest.yaml @@ -9,6 +9,8 @@ service_account: functions: - name: extraction description: Extraction function for the template snap-in + - name: install_initial_domain_mapping + description: Create blueprint and install initial domain mapping keyring_types: - id: example-connection @@ -30,3 +32,7 @@ imports: extractor_function: extraction allowed_connection_types: - example-connection + +hooks: + - type: activate + function: install_initial_domain_mapping