This repository has been archived by the owner on Jun 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from zapier/convert-auth-scripting
zapier convert: Generate different auth code based on scripting
- Loading branch information
Showing
14 changed files
with
1,037 additions
and
310 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
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
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 |
---|---|---|
@@ -1,12 +1,57 @@ | ||
{ | ||
const testTrigger = require('<%= TEST_TRIGGER_MODULE %>'); | ||
|
||
const getSessionKey = (z, bundle) => { | ||
const scripting = require('./scripting'); | ||
const legacyScriptingRunner = require('zapier-platform-legacy-scripting-runner')(scripting); | ||
|
||
// Do a get_session_info() from scripting. | ||
const getSessionEvent = { | ||
name: 'auth.session', | ||
}; | ||
return legacyScriptingRunner.runEvent(getSessionEvent, z, bundle) | ||
.then((getSessionResult) => { | ||
// IMPORTANT NOTE: | ||
// WB apps in scripting's get_session_info() allowed to return any object and that would be | ||
// added to the authData, but CLI apps require you to specifically define those. | ||
// That means that if you return more than one key from your scripting's get_session_info(), | ||
// you might need to manually tweak this method to return that value at the end of this method, | ||
// and also add more fields to the authentication definition. | ||
|
||
const resultKeys = Object.keys(getSessionResult); | ||
const firstKeyValue = (getSessionResult && resultKeys.length > 0) ? getSessionResult[resultKeys[0]] : getSessionResult; | ||
|
||
return { | ||
sessionKey: firstKeyValue, | ||
}; | ||
}); | ||
}; | ||
<% if (hasGetConnectionLabelScripting) { %> | ||
const getConnectionLabel = (z, bundle) => { | ||
const scripting = require('./scripting'); | ||
const legacyScriptingRunner = require('zapier-platform-legacy-scripting-runner')(scripting); | ||
|
||
// Do a get_connection_label() from scripting. | ||
const connectionLabelEvent = { | ||
name: 'auth.connectionLabel', | ||
}; | ||
return legacyScriptingRunner.runEvent(connectionLabelEvent, z, bundle); | ||
}; | ||
<% } %> | ||
const authentication = { | ||
// TODO: just an example stub - you'll need to complete | ||
type: 'session', | ||
test: AuthTest.operation.perform, | ||
test: testTrigger.operation.perform, | ||
fields: [ | ||
<%= FIELDS %> | ||
<%= FIELDS %> | ||
], | ||
sessionConfig: { | ||
perform: getSessionKey | ||
}, | ||
<% if (hasGetConnectionLabelScripting) { %> | ||
connectionLabel: getConnectionLabel | ||
<% } else { %> | ||
connectionLabel: '<%= CONNECTION_LABEL %>' | ||
} | ||
<% } %> | ||
}; | ||
|
||
module.exports = authentication; |
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,28 @@ | ||
const testTrigger = require('<%= TEST_TRIGGER_MODULE %>'); | ||
<% if (hasGetConnectionLabelScripting) { %> | ||
const getConnectionLabel = (z, bundle) => { | ||
const scripting = require('./scripting'); | ||
const legacyScriptingRunner = require('zapier-platform-legacy-scripting-runner')(scripting); | ||
|
||
// Do a get_connection_label() from scripting. | ||
const connectionLabelEvent = { | ||
name: 'auth.connectionLabel', | ||
}; | ||
return legacyScriptingRunner.runEvent(connectionLabelEvent, z, bundle); | ||
}; | ||
<% } %> | ||
const authentication = { | ||
// TODO: just an example stub - you'll need to complete | ||
type: '<%= TYPE %>', | ||
test: testTrigger.operation.perform, | ||
fields: [ | ||
<%= FIELDS %> | ||
], | ||
<% if (hasGetConnectionLabelScripting) { %> | ||
connectionLabel: getConnectionLabel | ||
<% } else { %> | ||
connectionLabel: '<%= CONNECTION_LABEL %>' | ||
<% } %> | ||
}; | ||
|
||
module.exports = authentication; |
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.