Cegid Y2 scripts
Reference of the Cegid Retail Y2 mapper, advisor repository and connection interceptor scripts: registration, handlers, header copying and examples.
Three scripts adjust the Cegid Retail Y2 connector. The mapper maps customer data between Cegid and the wallet account, beyond the default mapping. The advisor repository narrows and reshapes the list of salespersons Cegid returns. The connection interceptor sees every call the connector makes to Cegid. This page is the reference for extensions.cegid.y2.mapper, extensions.cegid.y2.advisorRepository and extensions.cegid.y2.connectionInterceptor. The connector, the Cegid customer object and the recipes for the free fields are on the Cegid connector pages; the rules shared by every connector script are in Connector scripts.
Registration
Key
Slot file
Methods (required in bold)
extensions.cegid.y2.mapper
cegid.y2.mapper.js
MapFromY2, MapToY2
extensions.cegid.y2.advisorRepository
cegid.y2.advisorRepository.js
Filter, Project
extensions.cegid.y2.connectionInterceptor
cegid.y2.connectionInterceptor.js
OnBeforeRequest, OnAfterRequest
The files sit in server/scripts/. The mapper and the advisor repository are edited in the Advanced tab of the Cegid Y2 page (Customer mapper and Advisors scripts). The interceptor has a slot file and an API but no tab, so it is edited in the advanced configuration. The slots are read and written with GET and PUT /api/{tenantId}/admin/extensions/cegid/y2/scripts.
When no script is registered for a key, the default behavior applies and nothing fails.
When it runs
MapFromY2
After a Cegid customer is read and the standard mapping is applied
MapToY2
After the consent mapping, before the customer is written. A create or an update runs both methods, because the record is read back after writing
Filter, Project
For each salesperson, on every advisor list request, after the connector has kept only the active salespersons of the requested store
OnBeforeRequest, OnAfterRequest
On every call to Cegid, so anything slow in them slows the whole connector
A create or an update runs both mappers, in this order:
Handlers
MapFromY2
data, account
nothing
Required
Synchronous
MapToY2
account, data
nothing
Required
Synchronous
Filter
advisor
true to keep the salesperson
Required
Synchronous
Project
advisor
an advisor, or null for the default
Optional
Synchronous
OnBeforeRequest
url, headers, content
a promise of { Url, Headers, Content }
Required
Asynchronous: declare it async
OnAfterRequest
soapAction, content
a promise of the response body, as a string
Required
Asynchronous: declare it async
Mapper.
datais the Cegid customer (CustomerData), with PascalCase members such asdata.EmailData.Email;accountis the flat wallet account. The methods change their arguments in place and return nothing. Both are required: register an empty function for the direction the script does not use. Anasyncmapper is not awaited, so changes made after anawaitare lost.Null entries. Null entries the script adds to
UserDefinedBooleans,UserDefinedDates,UserDefinedTexts,UserDefinedValuesorUserFieldsare removed before the customer is sent. Other arrays are sent as they are.Advisor repository.
advisoris the Cegid salesperson, with members such asId,FirstName,LastNameandStoreId.Filterreturns a boolean.Projectis optional and returns{ AdvisorId, DisplayName }; returningnullkeeps the default projection, the salesperson'sIdandFirstName LastName.Interceptor.
OnBeforeRequestmust return{ Url, Headers, Content }. The connector replaces the URL and all headers with what it returns, so the script copies the headers it received, changes what it needs and keepsSOAPAction.OnAfterRequestreturns the body of the response as a string.
The raw Cegid response is available while writing a mapping under debug.y2.customer, with equivalents for loyalty, sales documents and cash operations. These keys are a development aid and cannot be used in a pass template.
Errors and edge cases
A required method is missing: the call fails with
method <Name> missingwhen the connector reaches it. A mapper that registers only one direction fails on the other.A nested block is absent: blocks the default mapping does not fill, such as
UserDefinedData, are absent: create them before writing into them, or the whole save fails.MapToY2receives a new record built from the account, not the one stored in Cegid.The interceptor drops a header: the header is removed from the call. Without
SOAPAction, the request is sent without it and the call then fails with an error, because the response step reads that header.A script throws: the error reaches the connector operation that called it.
Example
The mapper writes the installation state of the wallet passes into a free table of the customer record, with an explicit 000 when no pass is installed, and maps the language through one table used in both directions.
The entity is flat: the language is the key neo.lng, read with brackets, not account.neo?.lng. The installation keys neo.pass.Apple.state and neo.pass.Google.state exist only when the connector writes back on an installation change, which is the Update customer on pass added / removed setting (Pass events, on by default) of the Cegid advanced configuration. The Cegid language codes are defined per Cegid database: the ones above are placeholders. The prefix neostore is the platform's former name and is kept in technical identifiers.
The connection interceptor below injects a header and keeps every header it received, including SOAPAction:
The connector already keeps only the salespersons of the requested store. The advisor repository below also hides technical accounts whose identifier starts with WEB:
Common pitfalls
Cegid identifiers start at 0 while the labels a Cegid user sees start at 1:
Id: 0is the first free field.Consent values are
0to3, not booleans.An interceptor that returns new headers without copying the received ones removes
SOAPAction.A mapper writes into a block that is absent on a new customer.
FAQ
Last updated

