-
Notifications
You must be signed in to change notification settings - Fork 1
Updated shared files #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
7ce7f32
Adding /internal/airdrop.artifacts.upload-url endpoint to the mock De…
dusano c4ee9ad
Removing internal attribute (request_id) from the sent form data.
dusano a81a1ac
Merge branch 'devrev:main' into main
dusano ceb015a
Merge branch 'devrev:main' into main
dusano ae7223b
Fixing artifact_id in DevRev mock server.
dusano d54d6a7
Proper constant name (devOrgID).
dusano f8bfb97
Merge branch 'devrev:main' into main
dusano cc2854f
Merge branch 'devrev:main' into main
dusano d7f4adc
Merge branch 'devrev:main' into main
dusano 04bf15a
Merge branch 'devrev:main' into main
dusano 2910da9
Merge branch 'devrev:main' into main
dusano 1680ad5
Merge branch 'devrev:main' into main
dusano a6419b9
Merge branch 'devrev:main' into main
dusano 87ea409
Chef CLI output schema
tjazerzen a3f0423
Merge branch 'main' into main
tjazerzen 6c9bee4
Add additional hints in the test requirements
tjazerzen 9e5559d
Remove unused test event
tjazerzen b83a050
Templates
tjazerzen eed6e6b
Incremental mode
tjazerzen 4e59fae
Fix mock devrev server
tjazerzen 1bfe263
Add transformation from FunctionInput to AirdropEvent
tjazerzen e1e2ffb
Improve conformance test logging
tjazerzen d140503
Ignore JS tests in `dist/`
tjazerzen 6bffa31
Update information in airdrop sdk library docs
tjazerzen c15dcd4
Fix docs for passing IDM
tjazerzen 7d19d62
Add hints for emitting events and transforming rich text
tjazerzen 8b29fec
Add external sync unit extraction docs
tjazerzen 589e3aa
Update function invocation
tjazerzen 4624db2
Metadata extraction docs is not needed ATM
tjazerzen 133cc8b
Update template plain source
tjazerzen 0b1cd8b
Updated naming for templates
tjazerzen 4c158b6
Simplify incremental mode instructions
tjazerzen 2ff6f4d
Update run conformance test script
tjazerzen bf3888d
Update templates
tjazerzen b7e6a4a
Simplify templates
tjazerzen 0b1fe45
Add instructions for emmitting events
tjazerzen 4dc639a
Revert docs to previous state
tjazerzen fd6469e
Simplify and make the template more maintainable
tjazerzen 87bd9c8
Merge branch 'main' into main
patricijabrecko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,52 @@ | ||
/** | ||
* Type definitions for DevRev function inputs and related types | ||
*/ | ||
|
||
export type Context = { | ||
// ID of the dev org for which the function is being invoked. | ||
dev_oid: string; | ||
// ID of the automation/command/snap-kit Action/Event Source for which the function is being invoked. | ||
source_id: string; | ||
// ID of the snap-in as part of which the function is being invoked. | ||
snap_in_id: string; | ||
// ID of the snap-in Version as part of which the function is being invoked. | ||
snap_in_version_id: string; | ||
// ID of the service account. | ||
service_account_id: string; | ||
// This secrets map would contain some secrets which platform would provide to the snap-in. | ||
// `service_account_token`: This is the token of the service account which belongs to this snap-in. This can be used to make API calls to DevRev. | ||
// `actor_session_token`: For commands, and snap-kits, where the user is performing some action, this is the token of the user who is performing the action. | ||
secrets: Record<string, string>; | ||
}; | ||
|
||
export type ExecutionMetadata = { | ||
// A unique id for the function invocation. Can be used to filter logs for a particular invocation. | ||
request_id: string; | ||
// Function name as defined in the manifest being invoked. | ||
function_name: string; | ||
// Type of event that triggered the function invocation as defined in manifest. | ||
event_type: string; | ||
// DevRev endpoint to which the function can make API calls. | ||
// Example : "https://api.devrev.ai/" | ||
devrev_endpoint: string; | ||
}; | ||
|
||
export type InputData = { | ||
// Map of organization inputs and their corresponding values stored in snap-in. | ||
// The values are passed as string and typing need to be handled by the function | ||
global_values: Record<string, string>; | ||
// Map of event sources and their corresponding ids stored in snap-in. | ||
// These could be used to schedule events on a schedule based event source. | ||
event_sources: Record<string, string>; | ||
}; | ||
|
||
// Event sent to our app. | ||
export type FunctionInput = { | ||
// Actual payload of the event. | ||
payload: Record<string, any>; | ||
// Context of the function invocation. | ||
context: Context; | ||
// Metadata of the function invocation. | ||
execution_metadata: ExecutionMetadata; | ||
input_data: InputData; | ||
}; |
This file contains hidden or 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,30 @@ | ||
import { AirdropEvent, AirdropMessage } from '@devrev/ts-adaas'; | ||
import { FunctionInput } from './types'; | ||
|
||
export function convertToAirdropEvent(fi: FunctionInput): AirdropEvent { | ||
// Create a properly structured AirdropMessage | ||
const airdropMessage: AirdropMessage = { | ||
connection_data: fi.payload.connection_data, | ||
event_context: { | ||
...fi.payload.event_context, | ||
...fi.context, | ||
request_id: fi.execution_metadata?.request_id, | ||
}, | ||
event_type: fi.payload.event_type, | ||
event_data: fi.payload.event_data || {}, | ||
}; | ||
|
||
return { | ||
context: { | ||
...fi.context, | ||
secrets: { | ||
service_account_token: fi.context.secrets?.service_account_token || '', | ||
...fi.context.secrets, | ||
}, | ||
}, | ||
payload: airdropMessage, | ||
execution_metadata: fi.execution_metadata, | ||
input_data: fi.input_data, | ||
}; | ||
} | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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,8 @@ | ||
Here are the rules when `EXTRACTION_DATA_START` or `EXTRACTION_DATA_CONTINUE` event is received by the snap-in: | ||
|
||
- If there's a timeout ("onTimeout" method in "spawn" method), the snap-in should emit an event with type `EXTRACTION_DATA_PROGRESS` (no "data" payload). | ||
- If the extraction is rate-limited by the external system, the snap-in should emit an event with type `EXTRACTION_DATA_DELAY` ("data" payload should contain attribute "delay" - delay in seconds as an integer). | ||
- If the extraction is successful and all the resources have been extracted, the snap-in should emit an event with type `EXTRACTION_DATA_DONE` (no "data" payload). | ||
- In case of unexpected error, the snap-in should emit an event with type `EXTRACTION_DATA_ERROR` ("data" payload should contain attribute "error" - error message as a string). | ||
|
||
NOTE: In all cases, only a single event should be emitted. |
This file contains hidden or 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 hidden or 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,63 @@ | ||
An _external sync unit_ refers to a single unit in the external system that is being airdropped to DevRev. | ||
In some systems, this is a project; in some it is a repository; in support systems it could be | ||
called a brand or an organization. | ||
What a unit of data is called and what it represents depends on the external system's domain model. | ||
It usually combines contacts, users, work-like items, and comments into a unit of domain objects. | ||
|
||
In the external sync unit extraction phase, the snap-in is expected to obtain a list of external | ||
sync units that it can extract from the external system API and send it to Airdrop in its response. | ||
|
||
External sync unit extraction is executed only during the initial import. | ||
|
||
## Triggering event | ||
|
||
Airdrop starts the external sync unit extraction by sending a message with the event type `EXTRACTION_EXTERNAL_SYNC_UNITS_START`. | ||
|
||
The snap-in must reply to Airdrop with an `EXTRACTION_EXTERNAL_SYNC_UNITS_DONE` message when finished, | ||
or `EXTRACTION_EXTERNAL_SYNC_UNITS_ERROR` if an error occurs. | ||
|
||
## Implementation | ||
|
||
|
||
The snap-in should emit the list of external sync units in the given format: | ||
|
||
```typescript | ||
const externalSyncUnits: ExternalSyncUnit[] = [ | ||
{ | ||
id: "devrev", | ||
name: "devrev", | ||
description: "Demo external sync unit", | ||
item_count: 100, | ||
}, | ||
]; | ||
``` | ||
|
||
- `id`: The unique identifier in the external system. | ||
- `name`: The human-readable name in the external system. | ||
- `description`: The short description if the external system provides it. | ||
- `item_count`: The number of items (issues, tickets, comments or others) in the external system. | ||
Item count should be provided if it can be obtained in a lightweight manner, such as by calling an API endpoint. | ||
If there is no such way to get it (for example, if the items would need to be extracted to count them), | ||
then the item count should be `-1` to avoid blocking the import with long-running queries. | ||
|
||
The snap-in must respond to Airdrop with a message, which contains a list of external sync units as a payload: | ||
|
||
```typescript | ||
await adapter.emit(ExtractorEventType.ExtractionExternalSyncUnitsDone, { | ||
external_sync_units: externalSyncUnits, | ||
}); | ||
``` | ||
|
||
or an error: | ||
|
||
```typescript | ||
await adapter.emit(ExtractorEventType.ExtractionExternalSyncUnitsError, { | ||
error: { | ||
message: "Failed to extract external sync units. Lambda timeout.", | ||
}, | ||
}); | ||
``` | ||
|
||
**The snap-in must always emit a single message.** | ||
|
||
To test your changes, start a new airdrop in the DevRev App. If external sync units extraction is successful, you should be prompted to choose an external sync unit from the list. |
This file contains hidden or 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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
The function is invoked by the runner.ts file. | ||
|
||
runner.ts processes events of type "any", which are basically events of type "AirdropEvent" with some additional fields, and passes the events to the function. You can ignore the additional fields. | ||
A function can be invoked synchronously or asynchronously. | ||
|
||
You need to implement the run method in your function. The run method is called when the function is invoked. The run method signature is defined below: | ||
|
||
```typescript | ||
async function run(events: []AirdropEvent): void; | ||
async function run(events: []FunctionInput): any; | ||
``` | ||
As of now, it's safe to assume that only one event is passed to the function at a time. The function can be invoked multiple times for multiple events. | ||
|
||
The value returned from the `run` method is passed back in synchronous execution modes, such as commands, snap kit actions, and event source synchronous execution. In asynchronous execution modes, such as automation execution, the return value is ignored. |
This file contains hidden or 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,24 @@ | ||
### Implementing Incremental Data Sync | ||
|
||
Incremental data synchronization retrieves only records that have been created or updated since the last successful sync. This process requires persistently tracking the timestamp of the last successful data extraction. On subsequent runs, this timestamp is used to query the source system for changes. | ||
|
||
Incremental mode should only be handled if the "event_type" is `EXTRACTION_DATA_START`. | ||
|
||
To check if we're in incremental mode, you should check if the value of `adapter.event.payload.event_context.mode` is `SyncMode.INCREMENTAL`. | ||
|
||
#### How implement incremental mode | ||
|
||
If we're in incremental mode, you should reset The Extraction State, indicating the sync hasn't been completed yet for all data types that we support incremental mode. | ||
|
||
Value of `adapter.state.lastSuccessfulSyncStarted` (of format ISO 8601 Extended Format with timezone) represents you the information since when you should query resources from the 3rd party API. | ||
|
||
To retrieve only the resources from the API that have to be updated, filtering on The API should be implemented. | ||
|
||
Note: | ||
- `adapter.state.lastSuccessfulSyncStarted` and `adapter.state.lastSyncStarted` are internal properties of the ts-adaas library, so no need to define it. This should be a read-only property. | ||
|
||
#### Remember the last successful sync time | ||
|
||
If the sync is successful, update the state object with the current time. | ||
|
||
Note: No need to modify any time-related properties in adapter.state object. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.