diff --git a/README.md b/README.md index 02a6d89..1ce5d9e 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,8 @@ Note that the username is your full email address. "appId": "the-long-uuid-in-the-url-that-designates-a-unique-commcare-project", "password": "shhh", "username": "test@openfn.org", - "applicationName": "some-proof-of-concept" + "applicationName": "some-proof-of-concept", + "hostUrl": "https://www.commcarehq.org" } ``` diff --git a/lib/Adaptor.js b/lib/Adaptor.js index 55babf3..7aad04d 100644 --- a/lib/Adaptor.js +++ b/lib/Adaptor.js @@ -125,9 +125,10 @@ function submit(formData) { var username = _state$configuration.username; var password = _state$configuration.password; var appId = _state$configuration.appId; + var hostUrl = _state$configuration.hostUrl; - var url = 'https://www.commcarehq.org/a/'.concat(applicationName, '/receiver/', appId, '/'); + var url = (hostUrl || "https://www.commcarehq.org").concat('/a/', applicationName, '/receiver/', appId, '/'); console.log("Posting to url: ".concat(url)); console.log("Raw JSON body: ".concat(JSON.stringify(jsonBody))); diff --git a/package.json b/package.json index 860cdd6..6c6a431 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "language-commcare", - "version": "1.0.4", + "version": "1.1.0", "description": "commcare Language Pack for OpenFn", "main": "lib/index.js", "scripts": { diff --git a/src/Adaptor.js b/src/Adaptor.js index 632b148..091855a 100644 --- a/src/Adaptor.js +++ b/src/Adaptor.js @@ -53,30 +53,33 @@ export function submit(formData) { const body = js2xmlparser("data", jsonBody); const { + // this should be called project URL. + // it is what lives after www.commcarehq.org/a/... applicationName, username, password, - appId + appId, + hostUrl } = state.configuration; - const url = `https://www.commcarehq.org/a/`.concat(applicationName, '/receiver/', appId, '/') + const url = (hostUrl || "https://www.commcarehq.org").concat('/a/', applicationName, '/receiver/', appId, '/'); console.log("Posting to url: ".concat(url)); console.log("Raw JSON body: ".concat(JSON.stringify(jsonBody))); console.log("X-form submission: ".concat(body)); return clientPost({ - url, - body, - username, - password - }) - .then((result) => { - console.log("Success:", result); - return {...state, - references: [result, ...state.references] - } - }) + url, + body, + username, + password + }) + .then((result) => { + console.log("Success:", result); + return {...state, + references: [result, ...state.references] + } + }); } }