Skip to content
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

App setting with 2 way SSL #19

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion sample-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ Sample app to demonstrate the usage of request templates in both front-end (`cli
|GET Method with Freshdesk API and authorization|`getContacts`|
|PUT Method with body|`replyTicket`|
|Customs iparams page|`iparamValidate`|
|GET Method with host dynamic substitution from Serverless|`dynamicHost`|
|GET Method with dynamic host substitution from Serverless|`dynamicHost`|
|GET Method with dynamic query params during runtime|`dynamicQueryParams`|
|GET Method with query params defined in requests.json|`listAllTickets`|
|POST Method with 2-way SSL and values configured in app settings|`visaMerchantSearch`|
|POST Method with 2-way SSL and dynamic host substitution values configured in app settings|`visaGetForexRate`|

### Files and Folders
.
Expand Down
43 changes: 42 additions & 1 deletion sample-app/app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,59 @@ async function invokeWithDynamicQueryParams() {
//Request method to list all tickets sorted by due by
let dueByTicketList = await client.request.invokeTemplate("listAllTickets", { "context": {}, "query": { "order_by": "due_by", "include": "stats" } })
console.log("Request method response to list tickets", dueByTicketList)
if(latestUpdateTicketList.response===dueByTicketList.response)
if (latestUpdateTicketList.response === dueByTicketList.response)
console.log("Request method responds with latest updated tickets with stats as query params defined in request.json have higher precedence")
//Request method responds with latest updated tickets with stats as query params defined in request.json have higher precedence
} catch (error) {
console.error(error)
}
}

async function invokeRequestMethodWith2WaySSL() {
//Request method which uses client-side certificates, host, path and authorization for 2-way SSL configured with app_settings
let merchantSearch = await client.request.invokeTemplate("visaMerchantSearch", {
body: JSON.stringify({
"searchOptions": {
"matchScore": "true",
"maxRecords": "10",
"matchIndicators": "true",
"proximity": [
"merchantName"
],
"wildCard": [
"merchantName"
]
},
"header": {
"startIndex": "0",
"requestMessageId": "VCO_GMR_001",
"messageDateTime": "2015-08-28T22:05:00.000"
},
"searchAttrList": {
"merchantPhoneNumber": "4153440351",
"merchantCity": "San Francisco",
"merchantCountryCode": "840",
"merchantPostalCode": "94107",
"paymentAcceptanceMethod": "F2F",
"visaStoreId": "161688518",
"merchantStreetAddress": "280 King St",
"merchantState": "CA",
"merchantName": "starbucks ",
"terminalType": "SWIPE"
},
"responseAttrList": [
"GNSTANDARD"
]
})
})
console.log("Response from request method using 2 way SSL", JSON.stringify(merchantSearch.response))
}

async function renderStarWarsInfo() {
await getStarWarsChar()
await getStarWarsCharDetails()
await searchForStarship()
await invokeSMIWithDynamicHost()
await invokeWithDynamicQueryParams()
await invokeRequestMethodWith2WaySSL()
}
35 changes: 17 additions & 18 deletions sample-app/config/iparams.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,28 @@
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script async src="{{{appclient}}}"></script>
<link rel="stylesheet" href="./assets/iparams.css" />
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script async src="{{{appclient}}}"></script>
<link rel="stylesheet" href="./assets/iparams.css" />
</head>

<body>
<main>
<h3>
Custom iparams page with Request template
</h3>
<fw-input required="true" type="text" label="Freshdesk domain" size="30"
placeholder="subdomain.freshdesk.com" class="domain" data-bind="product.domain"></fw-input>
<main>
<h3>
Custom iparams page with Request template
</h3>
<fw-input required="true" type="text" label="Freshdesk domain" size="30" placeholder="subdomain.freshdesk.com"
class="domain" data-bind="product.domain"></fw-input>

<fw-input label="Freshdesk API Key" type="password"
placeholder="Freshdesk Portal > Profile > Copy API Key" required="true" minlength="5" size="30"
class="secure-field" data-bind="product.api_key"></fw-input>
</main>
<fw-input label="Freshdesk API Key" type="password" placeholder="Freshdesk Portal > Profile > Copy API Key"
required="true" minlength="5" size="30" class="secure-field" data-bind="product.api_key"></fw-input>
</main>

<script src="./assets/iparams.js"></script>
<script type="module" src="https://unpkg.com/@freshworks/crayons@v4/dist/crayons/crayons.esm.js"></script>
<script nomodule src="https://unpkg.com/@freshworks/crayons@v4/dist/crayons/crayons.js"></script>
<script src="./assets/iparams.js"></script>
<script type="module" src="https://unpkg.com/@freshworks/crayons@v4/dist/crayons/crayons.esm.js"></script>
<script nomodule src="https://unpkg.com/@freshworks/crayons@v4/dist/crayons/crayons.js"></script>
</body>

</html>
222 changes: 129 additions & 93 deletions sample-app/config/requests.json
Original file line number Diff line number Diff line change
@@ -1,98 +1,134 @@
{
"getStarWarsPeople": {
"schema": {
"method": "GET",
"host": "swapi.dev",
"path": "/api/people"
}
},
"getStarWarsPeopleDetails": {
"schema": {
"protocol": "https",
"method": "GET",
"host": "swapi.dev",
"path": "/api/people/<%= context.id %>"
}
},
"starwarsStarshipSearch": {
"schema": {
"method": "GET",
"host": "swapi.dev",
"path": "/api/starships",
"query": {
"search": "<%= context.starshipname %>"
}
}
},
"getContacts": {
"schema": {
"method": "GET",
"host": "<%= iparam.subdomain %>.freshdesk.com",
"path": "/api/v2/contacts",
"headers": {
"Authorization": "Basic <%= encode(iparam.api_key) %>",
"Content-Type": "application/json"
}
}
},
"replyTicket": {
"schema": {
"protocol": "https",
"method": "POST",
"host": "<%= iparam.subdomain %>.freshdesk.com",
"path": "/api/v2/tickets/<%= context.id %>/reply",
"headers": {
"Authorization": "Basic <%= encode(iparam.api_key) %>",
"Content-Type": "application/json"
}
}
},
"iparamValidate": {
"schema": {
"protocol": "https",
"method": "GET",
"host": "<%= context.subdomain %>.freshdesk.com",
"path": "/api/v2/tickets",
"headers": {
"Authorization": "Basic <%= encode(context.api_key) %>",
"Content-Type": "application/json"
}
}
},
"dynamicHost": {
"schema": {
"protocol": "https",
"method": "GET",
"host": "<%= context.host %>",
"path": "/api/planets"
}
"getStarWarsPeople": {
"schema": {
"method": "GET",
"host": "swapi.dev",
"path": "/api/people"
}
},
"getStarWarsPeopleDetails": {
"schema": {
"protocol": "https",
"method": "GET",
"host": "swapi.dev",
"path": "/api/people/<%= context.id %>"
}
},
"starwarsStarshipSearch": {
"schema": {
"method": "GET",
"host": "swapi.dev",
"path": "/api/starships",
"query": {
"search": "<%= context.starshipname %>"
}
}
},
"getContacts": {
"schema": {
"method": "GET",
"host": "<%= iparam.subdomain %>.freshdesk.com",
"path": "/api/v2/contacts",
"headers": {
"Authorization": "Basic <%= encode(iparam.api_key) %>",
"Content-Type": "application/json"
}
}
},
"replyTicket": {
"schema": {
"protocol": "https",
"method": "POST",
"host": "<%= iparam.subdomain %>.freshdesk.com",
"path": "/api/v2/tickets/<%= context.id %>/reply",
"headers": {
"Authorization": "Basic <%= encode(iparam.api_key) %>",
"Content-Type": "application/json"
}
}
},
"iparamValidate": {
"schema": {
"protocol": "https",
"method": "GET",
"host": "<%= context.subdomain %>.freshdesk.com",
"path": "/api/v2/tickets",
"headers": {
"Authorization": "Basic <%= encode(context.api_key) %>",
"Content-Type": "application/json"
}
}
},
"dynamicHost": {
"schema": {
"protocol": "https",
"method": "GET",
"host": "<%= context.host %>",
"path": "/api/planets"
}
},
"dynamicQueryParams": {
"schema": {
"protocol": "https",
"method": "GET",
"host": "<%= iparam.subdomain %>.freshdesk.com",
"path": "/api/v2/search/tickets",
"headers": {
"Authorization": "Basic <%= encode(iparam.api_key) %>",
"Content-Type": "application/json"
}
}
},
"listAllTickets": {
"schema": {
"protocol": "https",
"method": "GET",
"host": "<%= iparam.subdomain %>.freshdesk.com",
"path": "/api/v2/tickets",
"headers": {
"Authorization": "Basic <%= encode(iparam.api_key) %>",
"Content-Type": "application/json"
},
"query": {
"order_type": "desc",
"order_by": "updated_at"
}
}
},
"visaGetForexRate": {
"schema": {
"method": "POST",
"protocol": "https",
"host": "<%= context.host %>",
"path": "<%= context.path %>",
"headers": {
"Content-Type": "application/json",
"Authorization": "Basic <%= encode(app_settings.visa.username + ':' + app_settings.visa.password) %>"
}
},
"dynamicQueryParams": {
"schema": {
"protocol": "https",
"method": "GET",
"host": "<%= iparam.subdomain %>.freshdesk.com",
"path": "/api/v2/search/tickets",
"headers": {
"Authorization": "Basic <%= encode(iparam.api_key) %>",
"Content-Type": "application/json"
}
}
"options": {
"security": {
"cert": "<%= app_settings.visa.cert %>",
"key": "<%= app_settings.visa.key %>"
}
}
},
"visaMerchantSearch": {
"schema": {
"method": "POST",
"protocol": "https",
"host": "<%= app_settings.visaMerchant.host %>",
"path": "<%= app_settings.visaMerchant.path %>",
"headers": {
"Content-Type": "application/json",
"Authorization": "Basic <%= encode(app_settings.visa.username + ':' + app_settings.visa.password) %>"
}
},
"listAllTickets": {
"schema": {
"protocol": "https",
"method": "GET",
"host": "<%= iparam.subdomain %>.freshdesk.com",
"path": "/api/v2/tickets",
"headers": {
"Authorization": "Basic <%= encode(iparam.api_key) %>",
"Content-Type": "application/json"
},
"query":{
"order_type":"desc",
"order_by":"updated_at"
}
}
"options": {
"security": {
"cert": "<%= app_settings.visa.cert %>",
"key": "<%= app_settings.visa.key %>"
}
}
}
}
4 changes: 3 additions & 1 deletion sample-app/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"replyTicket": {},
"dynamicHost": {},
"dynamicQueryParams": {},
"listAllTickets": {}
"listAllTickets": {},
"visaGetForexRate": {},
"visaMerchantSearch": {}
},
"functions": {
"usingDynamicHost": {
Expand Down
Loading