Skip to content

Instantly share code, notes, and snippets.

@ThomasFlorelli
Last active August 30, 2024 06:13
Show Gist options
  • Select an option

  • Save ThomasFlorelli/4541bf0e1b708954c322fe26f45cd98b to your computer and use it in GitHub Desktop.

Select an option

Save ThomasFlorelli/4541bf0e1b708954c322fe26f45cd98b to your computer and use it in GitHub Desktop.
import type { Knex } from 'knex';
const configurationId = crypto.randomUUID();
const configurationVersionId = crypto.randomUUID();
const organizationId = 'c2cb52c8-d836-4759-8508-139596c16991';
const productId = '18999891-77c7-4dc9-b3d2-593428a0f3b0';
const productVersionId = '302c68b4-4a1c-4823-b19e-9b0ea0f71be4';
const backendStateMachineId = crypto.randomUUID();
const frontendStateMachineId = crypto.randomUUID();
export async function seed(knex: Knex): Promise<void> {
await knex('configurations')
.withSchema('journey')
.insert({
id: configurationId,
name: 'BIKE AI',
organization_id: organizationId,
product_id: productId,
})
.onConflict('id')
.merge();
await knex('configuration_versions')
.withSchema('journey')
.insert({
configurationId,
font_family: 'INTER',
helpBlock: '**Une question ?**\n 06.44.55.22.11\n [email protected]',
id: configurationVersionId,
logo_id: 'd5eb4b22-31ab-46ae-8afd-ef2eb8c94390',
primary_color: '#3E5093',
product_version_id: productVersionId,
secondaryColor: '#ffffff',
})
.onConflict('id')
.merge();
await knex('configurations')
.withSchema('journey')
.where({ id: configurationId })
.update({ configurationVersionId });
await knex('backend_state_machines')
.withSchema('journey')
.insert({
configuration: {
states: [
{
key: 'init',
action: 'none',
nextKey: 'create_quote_request',
triggers: [
{
event:
'{ "executionId": executionId, "currentStateKey": `"wait_quote_creation"` }',
source: 'frontend-workflow',
},
],
mapPayload:
'{ "customProperties": state.context.customProperties || { "brand": state.context.brand, "price": state.context.price, "age": state.context.age, "id": state.context.id, "invoice": state.context.invoice, "model": state.context.model, "formula": state.context.formula }, "individual": { "firstName": state.context.firstName, "phone": state.context.phone, "email": state.context.email, "address": join(\' \' ,[state.context.address.streetNumber, state.context.address.streetAddress, state.context.address.postalCode, state.context.address.city, state.context.address.country]), "lastName": state.context.lastName, "birthdate": state.context.birthdate, "birthplace": state.context.birthplace, "type": `"INDIVIDUAL"` },\n"banner": {\n "type": `EXCLUSIONS`,\n"id": `1fce5c38-3f54-44d8-87f7-45ad564f8504`,\n "level": `WARNING`,\n "data": [{ "title": `price`, "content": `Le prix est supérieur ou égale à 5000€` },\n{ "title": `age`, "content": `L\'age du vélo est supérieur ou égale à 4ans ` }\n]\n }}',
},
{
key: 'create_quote_request',
retry: 1,
action: 'createQuoteRequest',
nextKey: 'add_quote_request_files',
runNext: true,
errorKey: 'nofity_fatal_error',
mapActionPayload:
'{ "executionId": executionId, "customProperties": customProperties, "productVersionId": productVersionId, "persons": [ { "person": { "personType": `"INDIVIDUAL"`, "firstName": individual.firstName, "phone": individual.phone, "email": individual.email, "address": individual.address, "lastName": individual.lastName, "birthdate": individual.birthdate, "birthplace": individual.birthplace }, "roles": [`"CONTACT"`, `"SUBSCRIBER"`] } ], "startsAt": `$day()`}',
mapResultPayload:
'{ "quoteRequestId": id, "ledgerAccountId": ledgerAccountId }',
},
{
key: 'add_quote_request_files',
action: 'upsertFilesMetadata',
nextKey: [
{
condition: {
value: '4',
operand: 'context.customProperties.age',
operator: 'GTE',
},
targetKey: 'update_banner',
},
{
targetKey: 'create_quote',
},
{
condition: {
value: '5000',
operand: 'context.customProperties.price',
operator: 'GTE',
},
targetKey: 'update_banner',
},
],
runNext: true,
errorKey: 'nofity_fatal_error',
mapActionPayload:
'{ "fileIds": fileIds || `[]`, "metadata": {"quoteRequestId": quoteRequestId} }',
},
{
key: 'create_quote',
retry: 1,
action: 'createQuote',
nextKey: 'update_front_auto',
runNext: true,
errorKey: 'nofity_fatal_error',
resumable: true,
mapActionPayload:
'{ "customProperties": customProperties, "quoteRequestId": quoteRequestId }',
mapResultPayload:
'{ "quoteId": id, "brokerFees": brokerFees, "periods": periods, "prices": prices }',
},
{
key: 'update_banner',
retry: 1,
action: 'updateQuoteRequestBanner',
nextKey: 'update_front_manual',
runNext: true,
resumable: false,
mapActionPayload:
'{\n "banner": banner,\n "id": quoteRequestId\n }',
mapResultPayload: '',
},
{
key: 'finalize_quote',
retry: 0,
action: 'finalizeQuote',
nextKey: 'update_front_with_prices',
runNext: true,
errorKey: 'nofity_fatal_error',
resumable: false,
mapActionPayload: '{"id": quoteId}',
mapResultPayload:
'{ "quoteId": id, "brokerFees": brokerFees,"periods": periods, "prices": prices }',
},
{
key: 'update_front_auto',
retry: 0,
action: 'notifyFrontend',
nextKey: 'finalize_quote',
runNext: true,
resumable: false,
mapActionPayload:
'{ "transitionKey": `"next"`, "targetStateKey": `"wait_quote_creation"`, "payload": {"canCreateQuote": `"false"`, "quoteRequestId": quoteRequestId, "quotePageTitle": `"Votre devis est en cours de création"`, "quotePageTexte": `"Votre devis s\'affichera automatiquement d\'ici quelques secondes. "` }, "executionId": executionId }',
mapResultPayload: '',
},
{
key: 'update_front_manual',
retry: 0,
action: 'notifyFrontend',
nextKey: 'wait_finalized_quote',
runNext: true,
resumable: false,
mapActionPayload:
'{ "transitionKey": `"next"`, "targetStateKey": `"wait_quote_creation"`, "payload": {"canCreateQuote": `"false"`, "quoteRequestId": quoteRequestId, "quotePageTitle": `"Merci pour votre demande"`, "quotePageTexte": `"Votre demande a bien été prise en compte et sera étudiée dans la plus brefs délais. Notre proposition vous sera envoyée par email directement. "` }, "executionId": executionId }',
mapResultPayload: '',
},
{
key: 'wait_finalized_quote',
action: 'none',
nextKey: 'update_front_with_prices',
triggers: [
{
event:
'{ "quoteRequestId": quoteRequestId, "status": `"FINALIZED"` }',
source: 'quote',
},
],
},
{
key: 'update_front_with_prices',
retry: 1,
action: 'notifyFrontend',
nextKey: 'wait_front_end_validate',
runNext: true,
mapActionPayload:
'{ "transitionKey": `"next"`, "targetStateKey": `"wait_quote_ready"`, "payload": { "brokerFees": brokerFees,"periods": periods, "prices": prices, "quoteId": quoteId, "quoteRequestId": quoteRequestId }, "executionId": executionId }',
},
{
key: 'nofity_fatal_error',
retry: 1,
action: 'notifyFrontend',
mapActionPayload:
'{ "transitionKey": `"fatal"`, "targetStateKey": `"wait_quote_creation"`, "executionId": executionId }',
},
{
key: 'wait_front_end_validate',
action: 'none',
nextKey: 'approve_quote',
triggers: [
{
event:
'{ "executionId": executionId, "currentStateKey": `"esign_preparing"` }',
source: 'frontend-workflow',
},
],
},
{
key: 'approve_quote',
retry: 1,
action: 'approveQuote',
nextKey: 'esign_preparing',
runNext: true,
errorKey: 'notify_esign_error',
mapActionPayload: '{ "id": quoteId }',
},
{
key: 'notify_esign_error',
retry: 1,
action: 'notifyFrontend',
mapActionPayload:
'{ "transitionKey": `"fatal"`, "targetStateKey": `"esign_processing"`, "executionId": executionId }',
},
{
key: 'esign_preparing',
action: 'none',
nextKey: 'notify_esign_ready',
triggers: [
{
event: '{ "quoteId": quoteId, "status": `"SIGN_SUBMITTED"` }',
source: 'policy',
},
],
mapPayload:
'{ "endsAt": endsAt, "policyId": id, "policyReference": reference, "policySigners": signers, "startsAt": startsAt }',
},
{
key: 'notify_esign_ready',
retry: 1,
action: 'notifyFrontend',
nextKey: 'wait_esign_success',
runNext: true,
mapActionPayload:
'{ "transitionKey": `"next"`, "targetStateKey": `"esign_preparing"`, "payload": { "signers": policySigners, "policyId": policyId, "policyReference": policyReference }, "executionId": executionId }',
},
{
key: 'wait_esign_success',
action: 'none',
nextKey: 'wait_esign_processing',
triggers: [
{
event: '{ "id": policyId, "status": `"SIGNED"` }',
source: 'policy',
},
],
mapPayload: '{ "policySigners": signers }',
},
{
key: 'wait_esign_processing',
action: 'none',
nextKey: 'notify_esign_success',
triggers: [
{
event:
'{ "executionId": executionId, "currentStateKey": `"esign_processing"` }',
source: 'frontend-workflow',
},
],
},
{
key: 'notify_esign_success',
retry: 1,
action: 'notifyFrontend',
nextKey: 'wait_payment_preparing',
runNext: true,
mapActionPayload:
'{ "transitionKey": `"next"`, "targetStateKey": `"esign_processing"`, "payload": `{}`, "executionId": executionId }',
},
{
key: 'wait_payment_preparing',
action: 'none',
nextKey: 'create_payment_method_checkout_url',
triggers: [
{
event:
'{ "executionId": executionId, "currentStateKey": `"payment_preparing"` }',
source: 'frontend-workflow',
},
],
},
{
key: 'create_payment_method_checkout_url',
action: 'getAddPaymentMethodUrlForLedger',
nextKey: 'notify_payment_ready',
runNext: true,
errorKey: 'notify_payment_preparing_error',
mapActionPayload:
'{ "productId": productId, "executionId": executionId, "accountId": accountId, "ledgerAccountId": ledgerAccountId }',
mapResultPayload: '{ "paymentMethodCheckoutURL": url }',
},
{
key: 'notify_payment_preparing_error',
retry: 1,
action: 'notifyFrontend',
mapActionPayload:
'{ "transitionKey": `"fatal"`, "targetStateKey": `"payment_preparing"`, "payload": `{}`, "executionId": executionId }',
},
{
key: 'notify_payment_ready',
action: 'notifyFrontend',
nextKey: 'wait_payment_success',
runNext: true,
mapActionPayload:
'{ "transitionKey": `"next"`, "targetStateKey": `"payment_preparing"`, "payload": { "paymentMethodCheckoutURL": paymentMethodCheckoutURL }, "executionId": executionId }',
},
{
key: 'wait_payment_success',
action: 'none',
nextKey: 'wait_payment_processing',
triggers: [
{
event:
'{ "event": `"payments.paymentMethodSetupSucceeded"`, "ledgerAccountId": ledgerAccountId }',
source: 'payment',
},
],
mapPayload:
'{ "paymentMethodLabel": paymentMethodInfo.last4Digits, "paymentMethodType": paymentMethodInfo.type }',
},
{
key: 'wait_payment_processing',
action: 'none',
nextKey: 'approve_policy',
triggers: [
{
event:
'{ "executionId": executionId, "currentStateKey": `"payment_processing"` }',
source: 'frontend-workflow',
},
],
},
{
key: 'approve_policy',
retry: 1,
action: 'approvePolicy',
nextKey: 'check_aml',
runNext: true,
errorKey: 'notify_payment_processing_error',
mapActionPayload: '{ "id": policyId }',
},
{
key: 'check_aml',
retry: 1,
action: 'amlCheck',
nextKey: 'notify_payment_success',
runNext: true,
errorKey: 'notify_payment_processing_error',
mapActionPayload:
'{"birthdate": individual.birthdate || persons[0].person.birthdate, "endDate": rentalEndingAt, "kind": `"PERSON"`, "name": join(\' \', [individual.firstName || persons[0].person.firstName, individual.lastName || persons[0].person.lastName]) }',
mapResultPayload: '{ "amlRecordId": id }',
},
{
key: 'notify_payment_processing_error',
retry: 1,
action: 'notifyFrontend',
mapActionPayload:
'{ "transitionKey": `"fatal"`, "targetStateKey": `"payment_processing"`, "executionId": executionId }',
},
{
key: 'notify_payment_success',
action: 'notifyFrontend',
nextKey: 'end',
runNext: true,
mapActionPayload:
'{ "transitionKey": `"next"`, "targetStateKey": `"payment_processing"`, "executionId": executionId, "payload": { "endsAt": endsAt, "paymentMethodLabel": paymentMethodLabel, "paymentMethodType": paymentMethodType, "startsAt": startsAt } }',
},
{
key: 'end',
action: 'none',
},
],
initialState: 'init',
initialContext: {
accountId: 'acct_1KsjQ4B1tfWUx9df',
},
},
configurationVersionId,
id: backendStateMachineId,
})
.onConflict('id')
.merge();
await knex('frontend_state_machines')
.withSchema('journey')
.insert({
configuration: {
states: [
{
key: 'welcome',
item: {
text: 'Bienvenue ! Assurez votre vélo electrique en quelques clics !',
type: 'PAGE',
title: 'Bienvenue',
},
title: 'Bienvenue',
transitions: [
{
key: 'next',
meta: {
assign: 'ASSIGN',
},
conditions: [
{
operand: 'data.context.preferForms',
operator: 'EQ',
target: 'my_bike',
value: 'true',
withComparison: true,
},
{
target: 'assistant',
withComparison: false,
},
],
type: 'CONDITIONAL',
},
],
},
{
key: 'assistant',
item: {
type: 'ASSISTANT',
assistantId: '{OPENAI_ASSISTANT_ID}',
},
title: 'Assistant',
section: 'Assistant',
transitions: [
{
key: 'previous',
target: 'welcome',
},
{
key: 'next',
meta: {
assign: 'ASSIGN',
},
target: 'formula',
},
],
},
{
key: 'my_bike',
item: {
type: 'FORM',
formId: '2a80f893-2de2-45f9-b14f-af127718e7cc',
},
title: 'Mon vélo',
section: 'Mon vélo',
transitions: [
{
key: 'previous',
target: 'welcome',
},
{
key: 'next',
meta: {
assign: 'ASSIGN',
},
conditions: [
{
value: 'Oui',
target: 'bill_document',
operand: 'data.invoice',
operator: 'EQ',
},
{
target: 'information',
},
],
},
],
},
{
key: 'information',
item: {
type: 'FORM',
formId: 'ae788334-748c-411f-a2ba-cf006820b8d9',
},
title: 'Mes informations',
section: 'Mes informations',
transitions: [
{
key: 'previous',
meta: {
assign: 'ASSIGN',
},
target: 'my_bike',
},
{
key: 'next',
meta: {
assign: 'ASSIGN',
},
target: 'formula',
},
],
},
{
key: 'bill_document',
item: {
type: 'DOCUMENTS',
title: 'Finalisation de votre dossier',
categories: ['Facture'],
},
title: 'Vos informations - Justificatifs',
section: 'Vos informations',
transitions: [
{ key: 'previous', target: 'my_bike' },
{ key: 'next', target: 'information' },
],
},
{
key: 'formula',
item: {
additionalInformations: {
title: 'Besoin de réfléchir ?',
entries: [
{
icon: 'DEFAULT',
title:
"[Consulter la fiche d'information](https://drive.google.com/file/d/1ucnucA6K8nC5Gxlv3-FrD_FOWIY4Vl0u/view?usp=sharing)",
},
{
icon: 'DEFAULT',
title:
"[Consulter la notice d'information](https://drive.google.com/file/d/1-BsQc0Nk1wUzH3EgDlJJy-TVm-Ee9HeS/view?usp=sharing)",
},
{
icon: 'DEFAULT',
title:
"[Consulter le document d'information](https://drive.google.com/file/d/19cA3qKtUTsH0EnbcYQvfIPdstFTFMtN1/view?usp=sharing)",
},
{
icon: 'PHONE',
title: '[Discutons-en 01 23 45 67 89](tel:0123456789)',
},
],
},
description: null,
details: [
{
title: 'Offres',
type: 'HEADER',
values: [
{
data: 'Casse uniquement',
disabled: false,
type: 'ID',
},
{
data: 'Vol uniquement',
disabled: false,
type: 'ID',
},
{
data: 'Casse et Vol',
disabled: false,
type: 'ID',
},
],
},
{
title: 'Garanties casse',
type: 'SECTION',
},
{
title:
'Couverture des frais liés aux dommages matériels imprévisibles et soudains altérant le fonctionnement du bien assuré, y comprise le vendalisme.',
type: 'ROW',
values: [
{
data: {
subtitle: null,
title: 'Couvert',
},
disabled: false,
},
{
data: {
subtitle: null,
title: 'Couvert',
},
disabled: false,
},
{
data: {
subtitle: null,
title: 'Couvert',
},
disabled: false,
},
],
},
{
title: 'Garanties démo',
type: 'SECTION',
},
{
title:
'Couverture en cas de soustraction, par agression ou par effraction, du bien assuré par un tiers. Le vol partiel est aussi couvert (un élément du bien assuré a été volé).',
type: 'ROW',
values: [
{
data: {
subtitle: null,
title: '-',
},
disabled: false,
},
{
data: {
subtitle: null,
title: 'Couvert',
},
disabled: false,
},
{
data: {
subtitle: null,
title: 'Couvert',
},
disabled: false,
},
],
},
{
title: 'Franchise',
type: 'SECTION',
},
{
title:
'Franchise minimum de 50 € pour les offres basique et classique.',
type: 'ROW',
values: [
{
data: {
subtitle: null,
title: '20%',
},
disabled: false,
},
{
data: {
subtitle: null,
title: '10%',
},
disabled: false,
},
{
data: {
subtitle: null,
title: 'Aucune',
},
disabled: false,
},
],
},
{
title: 'Assistance',
type: 'SECTION',
},
{
title:
'Remboursement des frais de transport permettant à l’adhérent de réaliser le trajet entre le lieu de survenance du vol ou de la casse et son domicile.',
type: 'ROW',
values: [
{
data: {
subtitle: null,
title: '-',
},
disabled: false,
},
{
data: {
subtitle: null,
title: 'Inclus',
},
disabled: false,
},
{
data: {
subtitle: null,
title: 'Inclus',
},
disabled: false,
},
],
},
],
fieldName: 'formula',
pricerProperties:
'{ "age": age, "brand": brand, "formula": formula, "id": id, "invoice": invoice, "model": model, "price": price }',
title: null,
type: 'OFFERS',
},
title: 'Choix de la formule',
section: 'Choix de la formule',
transitions: [
{
key: 'previous',
meta: {
assign: 'ASSIGN',
},
target: 'assistant',
},
{
key: 'next',
meta: {
assign: 'ASSIGN',
},
target: 'wait_quote_creation',
},
],
},
{
key: 'wait_quote_creation',
item: {
text: 'Devis en cours de création',
type: 'LOADER',
title: 'Veuillez patienter',
messages: [
{
icon: 'AddCardIcon',
message: 'Nous interrogeons l’assureur',
},
{
icon: 'AddCardIcon',
message: 'Nous comparons les offres',
},
],
},
title: 'Devis - En cours de création',
section: 'Votre devis',
resumable: true,
transitions: [
{
key: 'next',
meta: {
assign: 'ASSIGN',
origin: 'INTERNAL',
schema: {
type: 'object',
required: ['canCreateQuote', 'quoteRequestId'],
properties: {
canCreateQuote: {
type: 'string',
},
quotePageTexte: {
type: 'string',
},
quotePageTitle: {
type: 'string',
},
quoteRequestId: {
type: 'string',
},
},
additionalProperties: false,
},
},
target: 'wait_quote_ready',
type: 'SIMPLE',
},
],
},
{
key: 'wait_quote_ready',
item: {
text: '{{quotePageTexte}}',
title: '{{quotePageTitle}}',
type: 'PAGE',
},
title: 'Devis - En cours de création',
section: 'Votre devis',
resumable: true,
transitions: [
{
key: 'fatal',
meta: {
origin: 'INTERNAL',
},
target: 'fatal-error',
},
{
key: 'next',
meta: {
assign: 'ASSIGN',
origin: 'INTERNAL',
schema: {
type: 'object',
required: ['quoteId', 'prices'],
properties: {
prices: {
type: 'array',
items: {
type: 'object',
required: [
'commission',
'premium',
'tax',
'taxRate',
'conditions',
],
properties: {
tax: {
type: 'number',
},
premium: {
type: 'number',
},
taxRate: {
type: 'number',
},
commission: {
type: 'number',
},
conditions: {
type: 'array',
items: {
type: 'object',
required: ['name', 'value', 'conditionType'],
properties: {
name: {
type: 'string',
},
value: {
type: 'number',
},
conditionType: {
type: 'string',
},
},
additionalProperties: true,
},
},
},
additionalProperties: true,
},
},
periods: {
type: 'array',
items: {
type: 'object',
required: ['amount', 'commission', 'dueAt'],
properties: {
dueAt: {
type: 'string',
},
amount: {
type: 'number',
},
commission: {
type: 'number',
},
},
},
},
quoteId: {
type: 'string',
},
brokerFees: {
type: 'array',
items: {
type: 'object',
required: ['amount', 'label', 'tax', 'taxRate'],
properties: {
amount: {
type: 'integer',
},
label: {
type: 'string',
},
tax: {
type: 'integer',
},
taxRate: {
type: 'number',
},
},
additionalProperties: true,
},
},
quoteRequestId: {
type: 'string',
},
},
additionalProperties: false,
},
},
target: 'quote_validation',
},
],
},
{
key: 'fatal-error',
item: {
text: "Nous vous invitons à contacter un administrateur en lui fournissant la référence de votre parcours située dans l'URL de cette page (`https://journey.seyna.dev/${reference}`) afin de débloquer la situation.",
type: 'PAGE',
title: 'Echec de finalization du devis',
},
title: 'Echec de la création de devis',
section: 'Demande de devis',
transitions: [],
},
{
key: 'quote_validation',
item: {
brokerFeesPath: 'brokerFees',
clauses:
"En cochant cette case, je reconnais avoir pris connaissance du Document d'information, de la fiche d'information et de conseil précontractuelle et de la Notice d'information.",
highlightsPath:
'__seyna.offers.options | @[?id == $.formula].highlights[]',
priceFrequency: '/ an',
pricesPath: 'prices',
priceProperties: [
{
label: 'Marque',
value: 'brand',
},
{
label: 'Modèle',
value: 'model',
},
{
label: 'Formule',
value: 'formula',
},
],
titlePrice:
'__seyna.offers.options | @[?id == $.formula].title | [0]',
type: 'PRICES',
},
title: 'Votre devis',
section: 'Votre devis',
transitions: [
{
key: 'next',
meta: {
assign: '{ "acceptQuoteClauses": acceptClauses }',
schema: {
type: 'object',
required: ['acceptClauses'],
properties: {
acceptClauses: {
type: 'boolean',
const: true,
},
},
additionalProperties: false,
},
},
target: 'esign_preparing',
},
],
},
{
key: 'esign_preparing',
item: {
type: 'ESIGN_V2',
status: 'PREPARING',
nextLabel: 'Signer mon contrat avec Yousign',
pricesPath: 'prices',
titlePrice:
'__seyna.offers.options | @[?id == $.formula].title | [0]',
brokerFeesPath: 'brokerFees',
priceFrequency: '/ an',
priceProperties: [
{
label: 'Marque',
value: 'brand',
},
{
label: 'Modèle',
value: 'model',
},
{
label: 'Formule',
value: 'formula',
},
],
},
title: 'Signature électronique',
section: 'Confirmation',
transitions: [
{
key: 'fatal',
meta: {
origin: 'INTERNAL',
},
target: 'esign_error',
},
{
key: 'next',
meta: {
assign:
'{ "policyId": policyId, "policyReference": policyReference, "sign": { "url": signers[0].signatureUrl } }',
origin: 'INTERNAL',
schema: {
type: 'object',
required: ['policyId', 'policyReference', 'signers'],
properties: {
signers: {
type: 'array',
items: {
type: 'object',
required: ['email', 'signatureUrl'],
properties: {
email: {
type: 'string',
},
signatureUrl: {
type: 'string',
},
},
additionalProperties: false,
},
},
policyId: {
type: 'string',
},
policyReference: {
type: 'string',
},
},
additionalProperties: false,
},
},
target: 'esign_ready',
},
],
},
{
key: 'esign_ready',
item: {
type: 'ESIGN_V2',
status: 'READY',
urlPath: 'sign.url',
nextLabel: 'Signer mon contrat avec Yousign',
pricesPath: 'prices',
titlePrice:
'__seyna.offers.options | @[?id == $.formula].title | [0]',
brokerFeesPath: 'brokerFees',
priceFrequency: '/ an',
priceProperties: [
{
label: 'Marque',
value: 'brand',
},
{
label: 'Modèle',
value: 'model',
},
{
label: 'Formule',
value: 'formula',
},
],
},
title: 'Signature électronique',
section: 'Confirmation',
transitions: [
{
key: 'next',
target: 'esign_processing',
},
],
},
{
key: 'esign_processing',
item: {
type: 'ESIGN_V2',
status: 'PROCESSING',
nextLabel: 'Signer mon contrat avec Yousign',
pricesPath: 'prices',
titlePrice:
'__seyna.offers.options | @[?id == $.formula].title | [0]',
brokerFeesPath: 'brokerFees',
priceFrequency: '/ an',
priceProperties: [
{
label: 'Marque',
value: 'brand',
},
{
label: 'Modèle',
value: 'model',
},
{
label: 'Formule',
value: 'formula',
},
],
},
title: 'Signature électronique',
section: 'Confirmation',
transitions: [
{
key: 'fatal',
meta: {
origin: 'INTERNAL',
},
target: 'esign_error',
},
{
key: 'next',
meta: {
origin: 'INTERNAL',
},
target: 'esign_success',
},
],
},
{
key: 'esign_success',
item: {
type: 'ESIGN_V2',
status: 'SUCCESS',
nextLabel: 'Passer au paiement',
pricesPath: 'prices',
titlePrice:
'__seyna.offers.options | @[?id == $.formula].title | [0]',
brokerFeesPath: 'brokerFees',
priceFrequency: '/ an',
priceProperties: [
{
label: 'Marque',
value: 'brand',
},
{
label: 'Modèle',
value: 'model',
},
{
label: 'Formule',
value: 'formula',
},
],
},
title: 'Signature électronique',
section: 'Confirmation',
transitions: [
{
key: 'next',
target: 'payment_preparing',
},
],
},
{
key: 'esign_error',
item: {
type: 'ESIGN_V2',
status: 'ERROR',
pricesPath: 'prices',
titlePrice:
'__seyna.offers.options | @[?id == $.formula].title | [0]',
brokerFeesPath: 'brokerFees',
priceFrequency: '/ an',
priceProperties: [
{
label: 'Marque',
value: 'brand',
},
{
label: 'Modèle',
value: 'model',
},
{
label: 'Formule',
value: 'formula',
},
],
},
title: 'Signature électronique',
section: 'Confirmation',
transitions: [],
},
{
key: 'payment_preparing',
item: {
type: 'PAYMENT_V2',
status: 'PREPARING',
nextLabel: 'Ajouter mon moyen de paiement',
pricesPath: 'prices',
titlePrice:
'__seyna.offers.options | @[?id == $.formula].title | [0]',
brokerFeesPath: 'brokerFees',
priceFrequency: '/ an',
priceProperties: [
{
label: 'Marque',
value: 'brand',
},
{
label: 'Modèle',
value: 'model',
},
{
label: 'Formule',
value: 'formula',
},
],
},
title: 'Paiement en ligne',
section: 'Confirmation',
transitions: [
{
key: 'fatal',
meta: {
origin: 'INTERNAL',
},
target: 'payment_error',
},
{
key: 'next',
meta: {
assign:
'{ "paymentMethodCheckoutURL": paymentMethodCheckoutURL }',
origin: 'INTERNAL',
schema: {
type: 'object',
required: ['paymentMethodCheckoutURL'],
properties: {
paymentMethodCheckoutURL: {
type: 'string',
},
},
additionalProperties: false,
},
},
target: 'payment_ready',
},
],
},
{
key: 'payment_ready',
item: {
type: 'PAYMENT_V2',
status: 'READY',
urlPath: 'paymentMethodCheckoutURL',
nextLabel: 'Ajouter mon moyen de paiement',
pricesPath: 'prices',
titlePrice:
'__seyna.offers.options | @[?id == $.formula].title | [0]',
brokerFeesPath: 'brokerFees',
priceFrequency: '/ an',
priceProperties: [
{
label: 'Marque',
value: 'brand',
},
{
label: 'Modèle',
value: 'model',
},
{
label: 'Formule',
value: 'formula',
},
],
},
title: 'Paiement en ligne',
section: 'Confirmation',
transitions: [
{
key: 'next',
target: 'payment_processing',
},
],
},
{
key: 'payment_processing',
item: {
type: 'PAYMENT_V2',
status: 'PROCESSING',
nextLabel: 'Ajouter mon moyen de paiement',
pricesPath: 'prices',
titlePrice:
'__seyna.offers.options | @[?id == $.formula].title | [0]',
brokerFeesPath: 'brokerFees',
priceFrequency: '/ an',
priceProperties: [
{
label: 'Marque',
value: 'brand',
},
{
label: 'Modèle',
value: 'model',
},
{
label: 'Formule',
value: 'formula',
},
],
},
title: 'Paiement en ligne',
section: 'Confirmation',
transitions: [
{
key: 'fatal',
meta: {
origin: 'INTERNAL',
},
target: 'payment_error',
},
{
key: 'next',
meta: {
assign:
'{ "endsAt": endsAt, "paymentMethodLabel": paymentMethodLabel, "paymentMethodType": paymentMethodType, "startsAt": startsAt }',
origin: 'INTERNAL',
schema: {
type: 'object',
required: [
'endsAt',
'paymentMethodLabel',
'paymentMethodType',
'startsAt',
],
properties: {
endsAt: {
type: 'string',
},
startsAt: {
type: 'string',
},
paymentMethodType: {
type: 'string',
},
paymentMethodLabel: {
type: 'string',
},
},
additionalProperties: false,
},
},
target: 'payment_success',
},
],
},
{
key: 'payment_success',
item: {
type: 'PAYMENT_V2',
status: 'SUCCESS',
nextLabel: 'Récapitulatif',
pricesPath: 'prices',
titlePrice:
'__seyna.offers.options | @[?id == $.formula].title | [0]',
brokerFeesPath: 'brokerFees',
priceFrequency: '/ an',
priceProperties: [
{
label: 'Marque',
value: 'brand',
},
{
label: 'Modèle',
value: 'model',
},
{
label: 'Formule',
value: 'formula',
},
],
paymentMethodTypePath: 'paymentMethodType',
paymentMethodLabelPath: 'paymentMethodLabel',
},
title: 'Paiement en ligne',
section: 'Confirmation',
transitions: [
{
key: 'next',
target: 'end',
},
],
},
{
key: 'payment_error',
item: {
type: 'PAYMENT_V2',
status: 'ERROR',
pricesPath: 'prices',
titlePrice:
'__seyna.offers.options | @[?id == $.formula].title | [0]',
brokerFeesPath: 'brokerFees',
priceFrequency: '/ an',
priceProperties: [
{
label: 'Marque',
value: 'brand',
},
{
label: 'Modèle',
value: 'model',
},
{
label: 'Formule',
value: 'formula',
},
],
},
title: 'Paiement en ligne',
section: 'Confirmation',
transitions: [],
},
{
key: 'end',
item: {
hero: 'Vous êtes désormais couvert par **Bike** pour votre location du **{{formatDate startsAt}}** au **{{formatDate endsAt}}**.',
text: "Votre contrat d'assurance porte le numéro:\n**{{policyReference}}**.",
type: 'PAGE',
title: 'Merci',
},
title: "C'est terminé",
section: 'Confirmation',
},
],
initialState: 'welcome',
initialContext: {
__seyna: {
offers: {
options: [
{
description:
'Remise en état ou indemnisation du vélo suite à un accident, ou une chute avec ou sans tiers, à un acte de vandalisme.',
highlights: [
{
rating: null,
title: 'Garanties casse',
},
{
rating: null,
title: 'Franchise 20%',
},
],
id: 'Casse uniquement',
priceFrequency: 'MONTHLY',
title: 'Basique',
},
{
description:
'Offre Basique + remplacement du vélo complet en cas de vol avec effraction ou agression.',
highlights: [
{
rating: null,
title: 'Garanties casse',
},
{
rating: null,
title: 'Garanties vol',
},
{
rating: null,
title: 'Franchise 10%',
},
],
id: 'Vol uniquement',
priceFrequency: 'MONTHLY',
title: 'Classique',
},
{
description: 'Garantie classique + 0 franchise',
highlights: [
{
rating: null,
title: 'Garanties casse',
},
{
rating: null,
title: 'Garanties vol',
},
{
rating: null,
title: 'Franchise 0 €',
},
],
id: 'Casse et Vol',
priceFrequency: 'MONTHLY',
title: 'Confort',
},
],
},
},
},
},
configurationVersionId,
id: frontendStateMachineId,
})
.onConflict('id')
.merge();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment