-
Notifications
You must be signed in to change notification settings - Fork 66
zapier convert: Generate different auth code based on scripting #185
Changes from 6 commits
7b50adc
fc4dc25
33ac7ce
0cb65c9
ecb1a36
73e2c37
990f1c9
9212231
f837e3a
fecf3c0
7b4f7e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
{ | ||
"actions": { | ||
"create_recipe": { | ||
"_dump_version": 1, | ||
"custom_fields_result_url": "https://wt-c396b46e7e285c63f4bd6d4f8d32dc2e-0.run.webtask.io/fields-output", | ||
"custom_fields_url": "https://wt-c396b46e7e285c63f4bd6d4f8d32dc2e-0.run.webtask.io/fields-input", | ||
"fields": { | ||
"name": { | ||
"choices": null, | ||
"default": null, | ||
"help_text": null, | ||
"label": "Name", | ||
"list": false, | ||
"parent_key": null, | ||
"placeholder": null, | ||
"prefill": null, | ||
"required": true, | ||
"searchfill": null, | ||
"send_in_json": true, | ||
"sort": null, | ||
"type_of": "Unicode" | ||
} | ||
}, | ||
"help_text": "Creates a new Recipe.", | ||
"hide": false, | ||
"important": true, | ||
"label": "Create Recipe", | ||
"noun": "Recipe", | ||
"sample_result_fields": [ | ||
{ | ||
"key": "authorId", | ||
"type": "int" | ||
}, | ||
{ | ||
"key": "id", | ||
"type": "int" | ||
}, | ||
{ | ||
"important": true, | ||
"key": "name", | ||
"type": "unicode" | ||
} | ||
], | ||
"url": "https://wt-c396b46e7e285c63f4bd6d4f8d32dc2e-0.run.webtask.io/recipe-create" | ||
} | ||
}, | ||
"auth_fields": {}, | ||
"general": { | ||
"auth_data": {}, | ||
"auth_label": "", | ||
"auth_mapping": {}, | ||
"auth_type": "Unknown Auth", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should try to render a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made an app https://zapier.com/developer/builder/app/79939/development and specified "No Auth" for the authentication. The dumped result (https://zapier.com/api/developer/v1/apps/79939/dump) is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, in that case let it be, then! |
||
"auth_urls": {}, | ||
"cloned_from_app_id": 731, | ||
"description": "Test WB app for `zapier convert`.", | ||
"homepage_url": null, | ||
"image_url": null, | ||
"platform_version": "2015-07-31T00:00:00", | ||
"subscribe_url": null, | ||
"test_trigger_key": "test_auth", | ||
"their_user_count": null, | ||
"title": "Test API Header Cloned 2017-10-26", | ||
"unsubscribe_url": null | ||
}, | ||
"js": null, | ||
"searches": {}, | ||
"triggers": { | ||
"test_auth": { | ||
"_dump_version": 1, | ||
"custom_fields_url": null, | ||
"data_source": "Polling", | ||
"fields": {}, | ||
"help_text": "Test auth trigger.", | ||
"hide": true, | ||
"hook_event": null, | ||
"hook_static_directions": "Log into your service and paste the below URL into the webhook setup field.", | ||
"important": false, | ||
"label": "Test Auth", | ||
"noun": "", | ||
"paging": false, | ||
"sample_result_fields": [], | ||
"url": "http://httpbin.org/basic-auth/user/passwd" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,10 @@ const getAuthType = (definition) => { | |
return authTypeMap[definition.general.auth_type]; | ||
}; | ||
|
||
const hasAuth = (definition) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be moved to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are separate functions because in some situations we only need to quickly check if the app needs authentication or not. I don't want to do all the unnecessary things in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright! |
||
return getAuthType(definition) !== 'custom' || !_.isEmpty(definition.auth_fields); | ||
}; | ||
|
||
const renderField = (definition, key, indent = 0) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
const type = definition.type && typesMap[definition.type.toLowerCase()] || 'string'; | ||
|
||
|
@@ -125,11 +129,11 @@ ${padding}}`; | |
}; | ||
|
||
const renderFields = (fields, indent = 0) => { | ||
const result = []; | ||
const results = []; | ||
_.each(fields, (field, key) => { | ||
result.push(renderField(field, key, indent)); | ||
results.push(renderField(field, key, indent)); | ||
}); | ||
return result.join(',\n'); | ||
return results.join(',\n'); | ||
}; | ||
|
||
const renderSampleField = (def) => { | ||
|
@@ -195,7 +199,7 @@ const renderAuthTemplate = (authType, definition) => { | |
hasGetConnectionLabelScripting, | ||
}; | ||
|
||
const templateFile = path.join(TEMPLATE_DIR, '/basic-auth.template.js'); | ||
const templateFile = path.join(TEMPLATE_DIR, '/simple-auth.template.js'); | ||
return renderTemplate(templateFile, templateContext); | ||
}; | ||
|
||
|
@@ -280,7 +284,7 @@ const renderAuth = (definition) => { | |
} | ||
}; | ||
|
||
// write authentiction.js | ||
// write authentication.js | ||
const writeAuth = (definition, newAppDir) => { | ||
const fileName = 'authentication.js'; | ||
return renderAuth(definition) | ||
|
@@ -549,23 +553,26 @@ const writeStepTest = (type, definition, key, legacyApp, newAppDir) => { | |
}; | ||
|
||
const renderIndex = (legacyApp) => { | ||
const _hasAuth = hasAuth(legacyApp); | ||
const templateContext = { | ||
AUTHENTICATION: '', | ||
HEADER: '', | ||
TRIGGERS: '', | ||
SEARCHES: '', | ||
CREATES: '', | ||
BEFORE_REQUESTS: getBeforeRequests(legacyApp), | ||
AFTER_RESPONSES: getAfterResponses(legacyApp), | ||
hasAuth: _hasAuth | ||
}; | ||
|
||
return getHeader(legacyApp) | ||
.then((header) => { | ||
templateContext.HEADER = header; | ||
|
||
const importLines = [ | ||
"const authentication = require('./authentication');" | ||
]; | ||
const importLines = []; | ||
|
||
if (_hasAuth) { | ||
importLines.push("const authentication = require('./authentication');"); | ||
} | ||
|
||
const dirMap = { | ||
trigger: 'triggers', | ||
|
@@ -673,7 +680,10 @@ const convertApp = (legacyApp, newAppDir) => { | |
promises.push(writeIndex(legacyApp, newAppDir)); | ||
promises.push(writePackageJson(legacyApp, newAppDir)); | ||
promises.push(writeScripting(legacyApp, newAppDir)); | ||
promises.push(writeAuth(legacyApp, newAppDir)); | ||
|
||
if (hasAuth(legacyApp)) { | ||
promises.push(writeAuth(legacyApp, newAppDir)); | ||
} | ||
|
||
return Promise.all(promises); | ||
}; | ||
|
@@ -682,6 +692,7 @@ module.exports = { | |
convertApp, | ||
renderAuth, | ||
renderField, | ||
renderIndex, | ||
renderSample, | ||
renderStep, | ||
renderTemplate, | ||
|
@@ -690,4 +701,5 @@ module.exports = { | |
getHeader, | ||
getBeforeRequests, | ||
getAfterResponses, | ||
hasAuth, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
basic-scripting.json
is same asbasic.json
except that it has aget_connection_info
method in scripting.