Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into socialnetworks
Browse files Browse the repository at this point in the history
  • Loading branch information
frederic34 committed Sep 30, 2019
2 parents c7120e9 + 33908af commit b87610a
Show file tree
Hide file tree
Showing 138 changed files with 7,618 additions and 395 deletions.
6 changes: 6 additions & 0 deletions .tx/config
Expand Up @@ -410,3 +410,9 @@ source_file = htdocs/langs/en_US/workflow.lang
source_lang = en_US
type = MOZILLAPROPERTIES

[dolibarr.zapier]
file_filter = htdocs/langs/<lang>/zapier.lang
source_file = htdocs/langs/en_US/zapier.lang
source_lang = en_US
type = MOZILLAPROPERTIES

1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -22,6 +22,7 @@ Following changes may create regressions for some external modules, but were nec
* Removed deprecated method actioncomm->add(), use create() instead
* If you have developed your own emailing target selector and used parent::add_to_target(...), you must now use parent::addToTargets(...)
* Removed function dol_micro_time. Use native PHP microtime instead.
* The trigger BON_PRELEVEMENT_CREATE has been renamed into DIRECT_DEBIT_ORDER_CREATE.


***** ChangeLog for 10.0.2 compared to 10.0.1 *****
Expand Down
7 changes: 7 additions & 0 deletions dev/examples/zapier/.gitignore
@@ -0,0 +1,7 @@
build
docs
node_modules
*.log
.environment
.env
.zapierapprc
7 changes: 7 additions & 0 deletions dev/examples/zapier/.travis.yml
@@ -0,0 +1,7 @@
language: node_js
node_js:
- 8.10.0
before_script: 'npm install -g zapier-platform-cli'
script: 'zapier test'
notifications:
email: false
56 changes: 56 additions & 0 deletions dev/examples/zapier/action.json
@@ -0,0 +1,56 @@
{
"table_rowid": "id",
"id": 6764,
"ref": null,
"type_id": "5",
"type_code": "AC_RDV",
"type": null,
"type_color": null,
"code": null,
"label": "azerty",
"datec": null,
"datem": null,
"authorid": null,
"usermodid": null,
"datep": 1555365600,
"datef": 1555538399,
"durationp": 172799,
"fulldayevent": 1,
"punctual": 1,
"percentage": "-1",
"location": "",
"transparency": 1,
"priority": 0,
"userassigned": {
"1": {
"id": "1",
"transparency": 1
}
},
"userownerid": "1",
"userdoneid": null,
"usertodo": null,
"userdone": null,
"socid": null,
"contactid": null,
"elementtype": "",
"icalname": null,
"icalcolor": null,
"actions": [],
"email_msgid": null,
"email_from": null,
"email_sender": null,
"email_to": null,
"email_tocc": null,
"email_tobcc": null,
"email_subject": null,
"errors_to": null,
"import_key": null,
"linkedObjectsIds": null,
"fk_project": 0,
"modelpdf": null,
"note_public": null,
"note_private": null,
"note": "wxcvbn",
"duree": 0
}
77 changes: 77 additions & 0 deletions dev/examples/zapier/authentication.js
@@ -0,0 +1,77 @@
/*jshint esversion: 6 */
const testAuth = (z , bundle) => {
const url = bundle.authData.url+'/api/index.php/login';
// Normally you want to make a request to an endpoint that is either specifically designed to test auth, or one that
// every user will have access to, such as an account or profile endpoint like /me.
// In this example, we'll hit httpbin, which validates the Authorization Header against the arguments passed in the URL path
const promise = z.request({
url: url,
});

// This method can return any truthy value to indicate the credentials are valid.
// Raise an error to show
return promise.then((response) => {
if (response.status === 401) {
throw new Error('The Session Key you supplied is invalid');
}
return response;
});
};

const getSessionKey = (z, bundle) => {
const url = bundle.authData.url + '/api/index.php/login';

const promise = z.request({
method: 'POST',
url: url,
body: {
login: bundle.authData.login,
password: bundle.authData.password,
}
});

return promise.then((response) => {
if (response.status === 401) {
throw new Error('The login/password you supplied is invalid');
}
const json = JSON.parse(response.content);
return {
sessionKey: json.success.token || 'secret'
};
});
};

module.exports = {
type: 'session',
// Define any auth fields your app requires here. The user will be prompted to enter this info when
// they connect their account.
fields: [
{
key: 'url',
label: 'Url of service',
required: true,
type: 'string'
},
{
key: 'login',
label: 'Login',
required: true,
type: 'string'
},
{
key: 'password',
label: 'Password',
required: true,
type: 'password'
}
],
// The test method allows Zapier to verify that the credentials a user provides are valid. We'll execute this
// method whenever a user connects their account for the first time.
test: testAuth,
// The method that will exchange the fields provided by the user for session credentials.
sessionConfig: {
perform: getSessionKey
},
// assuming "login" is a key returned from the test
connectionLabel: '{{login}}'
};
90 changes: 90 additions & 0 deletions dev/examples/zapier/creates/thirdparty.js
@@ -0,0 +1,90 @@
/*jshint esversion: 6 */
// create a particular thirdparty by name
const createThirdparty = async (z, bundle) => {
const apiurl = bundle.authData.url + '/api/index.php/thirdparties';

const response = await z.request({
method: 'POST',
url: apiurl,
body: JSON.stringify({
name: bundle.inputData.name,
name_alias: bundle.inputData.name_alias,
ref_ext: bundle.inputData.ref_ext,
ref_int: bundle.inputData.ref_int,
address: bundle.inputData.address,
zip: bundle.inputData.zip,
town: bundle.inputData.town,
country_code: bundle.inputData.country_code,
country_id: bundle.inputData.country_id,
country: bundle.inputData.country,
phone: bundle.inputData.phone,
email: bundle.inputData.email,
client: bundle.inputData.client,
fournisseur: bundle.inputData.fournisseur,
code_client: bundle.inputData.code_client,
code_fournisseur: bundle.inputData.code_fournisseur,
sens: 'fromzapier'
})
});
const result = z.JSON.parse(response.content);
// api returns an integer when ok, a json when ko
return result.response || {id: response};
};

module.exports = {
key: 'thirdparty',
noun: 'Thirdparty',

display: {
label: 'Create Thirdparty',
description: 'Creates a thirdparty.'
},

operation: {
inputFields: [
{key: 'name', required: true},
{key: 'name_alias', required: false},
{key: 'address', required: false},
{key: 'zip', required: false},
{key: 'town', required: false},
{key: 'email', required: false},
{key: 'client', type: 'integer', required: false},
{key: 'fournisseur', type: 'integer', required: false},
{key: 'code_client', required: false},
{key: 'code_fournisseur', required: false}
],
perform: createThirdparty,

sample: {
id: 1,
name: 'DUPOND',
name_alias: 'DUPOND Ltd',
address: 'Rue des Canaries',
zip: '34090',
town: 'MONTPELLIER',
phone: '0123456789',
fax: '2345678901',
email: 'robot@domain.com',
client: 1,
fournisseur: 0,
code_client: 'CU1903-1234',
code_fournisseur: 'SU1903-2345'
},

outputFields: [
{key: 'id', label: 'ID'},
{key: 'name', label: 'Name'},
{key: 'name_alias', label: 'Name alias'},
{key: 'address', label: 'Address'},
{key: 'zip', label: 'Zip'},
{key: 'town', label: 'Town'},
{key: 'phone', label: 'Phone'},
{key: 'fax', label: 'Fax'},
{key: 'email', label: 'Email'},
{key: 'client', label: 'Customer/Prospect 0/1/2/3'},
{key: 'fournisseur', label: 'Supplier 0/1'},
{key: 'code_client', label: 'Customer code'},
{key: 'code_fournisseur', label: 'Supplier code'}
]
}
};
73 changes: 73 additions & 0 deletions dev/examples/zapier/index.js
@@ -0,0 +1,73 @@
/*jshint esversion: 6 */
const triggerThirdparty = require('./triggers/thirdparty');
const triggerOrder = require('./triggers/order');
const triggerAction = require('./triggers/action');

const searchThirdparty = require('./searches/thirdparty');

const createThirdparty = require('./creates/thirdparty');

const authentication = require('./authentication');

// To include the session key header on all outbound requests, simply define a function here.
// It runs runs before each request is sent out, allowing you to make tweaks to the request in a centralized spot
const includeSessionKeyHeader = (request, z, bundle) => {
if (bundle.authData.sessionKey) {
request.headers = request.headers || {};
request.headers['DOLAPIKEY'] = bundle.authData.sessionKey;
}
return request;
};

// If we get a response and it is a 401, we can raise a special error telling Zapier to retry this after another exchange.
const sessionRefreshIf401 = (response, z, bundle) => {
if (bundle.authData.sessionKey) {
if (response.status === 401) {
throw new z.errors.RefreshAuthError('Session apikey needs refreshing.');
}
}
return response;
};

// We can roll up all our behaviors in an App.
const App = {
// This is just shorthand to reference the installed dependencies you have. Zapier will
// need to know these before we can upload
version: require('./package.json').version,
platformVersion: require('zapier-platform-core').version,

authentication: authentication,

// beforeRequest & afterResponse are optional hooks into the provided HTTP client
beforeRequest: [
includeSessionKeyHeader
],

afterResponse: [
sessionRefreshIf401
],

// If you want to define optional resources to simplify creation of triggers, searches, creates - do that here!
resources: {
},

// If you want your trigger to show up, you better include it here!
triggers: {
[triggerThirdparty.key]: triggerThirdparty,
[triggerOrder.key]: triggerOrder,
[triggerAction.key]: triggerAction
},

// If you want your searches to show up, you better include it here!
searches: {
[searchThirdparty.key]: searchThirdparty,
},

// If you want your creates to show up, you better include it here!
creates: {
[createThirdparty.key]: createThirdparty,
}
};

// Finally, export the app.
module.exports = App;

0 comments on commit b87610a

Please sign in to comment.