@webiny/api-form-builder-so-ddb-es 5.24.0 → 5.25.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/configurations.js.map +1 -0
- package/definitions/elasticsearch.js.map +1 -0
- package/definitions/form.js.map +1 -0
- package/definitions/settings.js.map +1 -0
- package/definitions/submission.js.map +1 -0
- package/definitions/system.js.map +1 -0
- package/definitions/table.d.ts +1 -1
- package/definitions/table.js.map +1 -0
- package/definitions/tableElasticsearch.js.map +1 -0
- package/index.js.map +1 -0
- package/operations/form/elasticsearchBody.js +1 -1
- package/operations/form/elasticsearchBody.js.map +1 -0
- package/operations/form/elasticsearchFields.js.map +1 -0
- package/operations/form/fields.js.map +1 -0
- package/operations/form/index.d.ts +2 -2
- package/operations/form/index.js +4 -4
- package/operations/form/index.js.map +1 -0
- package/operations/settings/index.d.ts +2 -2
- package/operations/settings/index.js.map +1 -0
- package/operations/submission/elasticsearchBody.js +1 -1
- package/operations/submission/elasticsearchBody.js.map +1 -0
- package/operations/submission/elasticsearchFields.js.map +1 -0
- package/operations/submission/index.d.ts +2 -2
- package/operations/submission/index.js +3 -3
- package/operations/submission/index.js.map +1 -0
- package/operations/system/createElasticsearchIndex.d.ts +2 -2
- package/operations/system/createElasticsearchIndex.js.map +1 -0
- package/operations/system/index.d.ts +2 -2
- package/operations/system/index.js.map +1 -0
- package/package.json +19 -19
- package/plugins/FormDynamoDbFieldPlugin.js.map +1 -0
- package/plugins/FormElasticsearchBodyModifierPlugin.js.map +1 -0
- package/plugins/FormElasticsearchFieldPlugin.js.map +1 -0
- package/plugins/FormElasticsearchQueryModifierPlugin.js.map +1 -0
- package/plugins/FormElasticsearchSortModifierPlugin.js.map +1 -0
- package/plugins/SubmissionElasticsearchBodyModifierPlugin.js.map +1 -0
- package/plugins/SubmissionElasticsearchFieldPlugin.js.map +1 -0
- package/plugins/SubmissionElasticsearchQueryModifierPlugin.js.map +1 -0
- package/plugins/SubmissionElasticsearchSortModifierPlugin.js.map +1 -0
- package/types.js.map +1 -0
- package/upgrades/5.16.0/index.d.ts +3 -0
- package/upgrades/5.16.0/index.js +1 -0
- package/upgrades/5.16.0/index.js.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["configurations.ts"],"names":["es","params","tenant","sharedIndex","process","env","ELASTICSEARCH_SHARED_INDEXES","index","prefix","ELASTIC_SEARCH_INDEX_PREFIX"],"mappings":";;;;;;eAQe;AACXA,EAAAA,EAAE,CAACC,MAAD,EAAyD;AACvD,UAAM;AAAEC,MAAAA;AAAF,QAAaD,MAAnB;AAEA,UAAME,WAAW,GAAGC,OAAO,CAACC,GAAR,CAAYC,4BAAZ,KAA6C,MAAjE;AACA,UAAMC,KAAK,GAAI,GAAEJ,WAAW,GAAG,MAAH,GAAYD,MAAO,eAA/C;AAEA,UAAMM,MAAM,GAAGJ,OAAO,CAACC,GAAR,CAAYI,2BAA3B;;AACA,QAAID,MAAJ,EAAY;AACR,aAAO;AAAED,QAAAA,KAAK,EAAEC,MAAM,GAAGD;AAAlB,OAAP;AACH;;AACD,WAAO;AAAEA,MAAAA;AAAF,KAAP;AACH;;AAZU,C","sourcesContent":["export interface ElasticsearchConfigParams {\n tenant: string;\n}\n\ninterface ElasticsearchConfig {\n index: string;\n}\n\nexport default {\n es(params: ElasticsearchConfigParams): ElasticsearchConfig {\n const { tenant } = params;\n\n const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === \"true\";\n const index = `${sharedIndex ? \"root\" : tenant}-form-builder`;\n\n const prefix = process.env.ELASTIC_SEARCH_INDEX_PREFIX;\n if (prefix) {\n return { index: prefix + index };\n }\n return { index };\n }\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["elasticsearch.ts"],"names":["createElasticsearchEntity","params","table","entityName","attributes","Entity","name","PK","partitionKey","SK","sortKey","index","type","data","TYPE"],"mappings":";;;;;;;;;;;AAAA;;;;;;AASO,MAAMA,yBAAyB,GAAIC,MAAD,IAAoB;AACzD,QAAM;AAAEC,IAAAA,KAAF;AAASC,IAAAA,UAAT;AAAqBC,IAAAA;AAArB,MAAoCH,MAA1C;AACA,SAAO,IAAII,uBAAJ,CAAW;AACdC,IAAAA,IAAI,EAAEH,UADQ;AAEdD,IAAAA,KAFc;AAGdE,IAAAA,UAAU;AACNG,MAAAA,EAAE,EAAE;AACAC,QAAAA,YAAY,EAAE;AADd,OADE;AAINC,MAAAA,EAAE,EAAE;AACAC,QAAAA,OAAO,EAAE;AADT,OAJE;AAONC,MAAAA,KAAK,EAAE;AACHC,QAAAA,IAAI,EAAE;AADH,OAPD;AAUNC,MAAAA,IAAI,EAAE;AACFD,QAAAA,IAAI,EAAE;AADJ,OAVA;AAaNE,MAAAA,IAAI,EAAE;AACFF,QAAAA,IAAI,EAAE;AADJ;AAbA,OAiBFR,UAAU,IAAI,EAjBZ;AAHI,GAAX,CAAP;AAuBH,CAzBM","sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { Attributes } from \"~/types\";\n\ninterface Params {\n table: Table;\n entityName: string;\n attributes: Attributes;\n}\n\nexport const createElasticsearchEntity = (params: Params) => {\n const { table, entityName, attributes } = params;\n return new Entity({\n name: entityName,\n table,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n index: {\n type: \"string\"\n },\n data: {\n type: \"map\"\n },\n TYPE: {\n type: \"string\"\n },\n\n ...(attributes || {})\n }\n });\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["form.ts"],"names":["createFormEntity","params","table","entityName","attributes","Entity","name","PK","partitionKey","SK","sortKey","TYPE","type","id","formId","tenant","locale","createdBy","ownedBy","savedOn","createdOn","slug","version","locked","published","publishedOn","status","fields","layout","stats","settings","triggers","webinyVersion"],"mappings":";;;;;;;;;;;AAAA;;;;;;AASO,MAAMA,gBAAgB,GAAIC,MAAD,IAAiC;AAC7D,QAA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W,EAAE;AACTb,QAAAA,IAAI,EAAE;AADG,OAjDP;AAoDNc,MAAAA,MAAM,EAAE;AACJd,QAAAA,IAAI,EAAE;AADF,OApDF;AAuDNe,MAAAA,MAAM,EAAE;AACJf,QAAAA,IAAI,EAAE;AADF,OAvDF;AA0DNgB,MAAAA,MAAM,EAAE;AACJhB,QAAAA,IAAI,EAAE;AADF,OA1DF;AA6DNiB,MAAAA,KAAK,EAAE;AACHjB,QAAAA,IAAI,EAAE;AADH,OA7DD;AAgENkB,MAAAA,QAAQ,EAAE;AACNlB,QAAAA,IAAI,EAAE;AADA,OAhEJ;AAmENmB,MAAAA,QAAQ,EAAE;AACNnB,QAAAA,IAAI,EAAE;AADA,OAnEJ;AAsENoB,MAAAA,aAAa,EAAE;AACXpB,QAAAA,IAAI,EAAE;AADK;AAtET,OAyEFR,UAAU,IAAI,EAzEZ;AAHI,GAAX,CAAP;AA+EH,CAjFM","sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { Attributes } from \"~/types\";\n\ninterface Params {\n table: Table;\n entityName: string;\n attributes: Attributes;\n}\n\nexport const createFormEntity = (params: Params): Entity<any> => {\n const { table, entityName, attributes } = params;\n return new Entity({\n table,\n name: entityName,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n TYPE: {\n type: \"string\"\n },\n id: {\n type: \"string\"\n },\n formId: {\n type: \"string\"\n },\n tenant: {\n type: \"string\"\n },\n locale: {\n type: \"string\"\n },\n createdBy: {\n type: \"map\"\n },\n ownedBy: {\n type: \"map\"\n },\n savedOn: {\n type: \"string\"\n },\n createdOn: {\n type: \"string\"\n },\n name: {\n type: \"string\"\n },\n slug: {\n type: \"string\"\n },\n version: {\n type: \"number\"\n },\n locked: {\n type: \"boolean\"\n },\n published: {\n type: \"boolean\"\n },\n publishedOn: {\n type: \"string\"\n },\n status: {\n type: \"string\"\n },\n fields: {\n type: \"list\"\n },\n layout: {\n type: \"list\"\n },\n stats: {\n type: \"map\"\n },\n settings: {\n type: \"map\"\n },\n triggers: {\n type: \"map\"\n },\n webinyVersion: {\n type: \"string\"\n },\n ...(attributes || {})\n }\n });\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["settings.ts"],"names":["createSettingsEntity","params","entityName","attributes","table","Entity","name","PK","partitionKey","SK","sortKey","TYPE","type","reCaptcha","domain","tenant","locale"],"mappings":";;;;;;;;;;;AAAA;;;;;;AASO,MAAMA,oBAAoB,GAAIC,MAAD,IAAiC;AACjE,QAAM;AAAEC,IAAAA,UAAF;AAAcC,IAAAA,UAAd;AAA0BC,IAAAA;AAA1B,MAAoCH,MAA1C;AACA,SAAO,IAAII,uBAAJ,CAAW;AACdC,IAAAA,IAAI,EAAEJ,UADQ;AAEdE,IAAAA,KAFc;AAGdD,IAAAA,UAAU;AACNI,MAAAA,EAAE,EAAE;AACAC,QAAAA,YAAY,EAAE;AADd,OADE;AAINC,MAAAA,EAAE,EAAE;AACAC,QAAAA,OAAO,EAAE;AADT,OAJE;AAONC,MAAAA,IAAI,EAAE;AACFC,QAAAA,IAAI,EAAE;AADJ,OAPA;AAUNC,MAAAA,SAAS,EAAE;AACPD,QAAAA,IAAI,EAAE;AADC,OAVL;AAaNE,MAAAA,MAAM,EAAE;AACJF,QAAAA,IAAI,EAAE;AADF,OAbF;AAgBNG,MAAAA,MAAM,EAAE;AACJH,QAAAA,IAAI,EAAE;AADF,OAhBF;AAmBNI,MAAAA,MAAM,EAAE;AACJJ,QAAAA,IAAI,EAAE;AADF;AAnBF,OAsBFT,UAAU,IAAI,EAtBZ;AAHI,GAAX,CAAP;AA4BH,CA9BM","sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { Attributes } from \"~/types\";\n\ninterface Params {\n table: Table;\n entityName: string;\n attributes: Attributes;\n}\n\nexport const createSettingsEntity = (params: Params): Entity<any> => {\n const { entityName, attributes, table } = params;\n return new Entity({\n name: entityName,\n table,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n TYPE: {\n type: \"string\"\n },\n reCaptcha: {\n type: \"map\"\n },\n domain: {\n type: \"string\"\n },\n tenant: {\n type: \"string\"\n },\n locale: {\n type: \"string\"\n },\n ...(attributes || {})\n }\n });\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["submission.ts"],"names":["createSubmissionEntity","params","table","entityName","attributes","Entity","name","PK","partitionKey","SK","sortKey","id","type","TYPE","data","meta","form","logs","createdOn","savedOn","ownedBy","tenant","locale","webinyVersion"],"mappings":";;;;;;;;;;;AAAA;;;;;;AASO,MAAMA,sBAAsB,GAAIC,MAAD,IAAiC;AACnE,QAAM;AAAEC,IAAAA,KAAF;AAASC,IAAAA,UAAT;AAAqBC,IAAAA;AAArB,MAAoCH,MAA1C;AACA,SAAO,IAAII,uBAAJ,CAAW;AACdH,IAAAA,KADc;AAEdI,IAAAA,IAAI,EAAEH,UAFQ;AAGdC,IAAAA,UAAU;AACNG,MAAAA,EAAE,EAAE;AACAC,QAAAA,YAAY,EAAE;AADd,OADE;AAINC,MAAAA,EAAE,EAAE;AACAC,QAAAA,OAAO,EAAE;AADT,OAJE;AAONC,MAAAA,EAAE,EAAE;AACAC,QAAAA,IAAI,EAAE;AADN,OAPE;AAUNC,MAAAA,IAAI,EAAE;AACFD,QAAAA,IAAI,EAAE;AADJ,OAVA;AAaNE,MAAAA,IAAI,EAAE;AACFF,QAAAA,IAAI,EAAE;AADJ,OAbA;AAgBNG,MAAAA,IAAI,EAAE;AACFH,QAAAA,IAAI,EAAE;AADJ,OAhBA;AAmBNI,MAAAA,IAAI,EAAE;AACFJ,QAAAA,IAAI,EAAE;AADJ,OAnBA;AAsBNK,MAAAA,IAAI,EAAE;AACFL,QAAAA,IAAI,EAAE;AADJ,OAtBA;AAyBNM,MAAAA,SAAS,EAAE;AACPN,QAAAA,IAAI,EAAE;AADC,OAzBL;AA4BNO,MAAAA,OAAO,EAAE;AACLP,QAAAA,IAAI,EAAE;AADD,OA5BH;AA+BNQ,MAAAA,OAAO,EAAE;AACLR,QAAAA,IAAI,EAAE;AADD,OA/BH;AAkCNS,MAAAA,MAAM,EAAE;AACJT,QAAAA,IAAI,EAAE;AADF,OAlCF;AAqCNU,MAAAA,MAAM,EAAE;AACJV,QAAAA,IAAI,EAAE;AADF,OArCF;AAwCNW,MAAAA,aAAa,EAAE;AACXX,QAAAA,IAAI,EAAE;AADK;AAxCT,OA2CFR,UAAU,IAAI,EA3CZ;AAHI,GAAX,CAAP;AAiDH,CAnDM","sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { Attributes } from \"~/types\";\n\ninterface Params {\n table: Table;\n entityName: string;\n attributes: Attributes;\n}\n\nexport const createSubmissionEntity = (params: Params): Entity<any> => {\n const { table, entityName, attributes } = params;\n return new Entity({\n table,\n name: entityName,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n id: {\n type: \"string\"\n },\n TYPE: {\n type: \"string\"\n },\n data: {\n type: \"map\"\n },\n meta: {\n type: \"map\"\n },\n form: {\n type: \"map\"\n },\n logs: {\n type: \"list\"\n },\n createdOn: {\n type: \"string\"\n },\n savedOn: {\n type: \"string\"\n },\n ownedBy: {\n type: \"map\"\n },\n tenant: {\n type: \"string\"\n },\n locale: {\n type: \"string\"\n },\n webinyVersion: {\n type: \"string\"\n },\n ...(attributes || {})\n }\n });\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["system.ts"],"names":["createSystemEntity","params","entityName","attributes","table","Entity","name","PK","partitionKey","SK","sortKey","version","type","tenant"],"mappings":";;;;;;;;;;;AAAA;;;;;;AASO,MAAMA,kBAAkB,GAAIC,MAAD,IAAiC;AAC/D,QAAM;AAAEC,IAAAA,UAAF;AAAcC,IAAAA,UAAd;AAA0BC,IAAAA;AAA1B,MAAoCH,MAA1C;AACA,SAAO,IAAII,uBAAJ,CAAW;AACdC,IAAAA,IAAI,EAAEJ,UADQ;AAEdE,IAAAA,KAFc;AAGdD,IAAAA,UAAU;AACNI,MAAAA,EAAE,EAAE;AACAC,QAAAA,YAAY,EAAE;AADd,OADE;AAINC,MAAAA,EAAE,EAAE;AACAC,QAAAA,OAAO,EAAE;AADT,OAJE;AAONC,MAAAA,OAAO,EAAE;AACLC,QAAAA,IAAI,EAAE;AADD,OAPH;AAUNC,MAAAA,MAAM,EAAE;AACJD,QAAAA,IAAI,EAAE;AADF;AAVF,OAaFT,UAAU,IAAI,EAbZ;AAHI,GAAX,CAAP;AAmBH,CArBM","sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { Attributes } from \"~/types\";\n\ninterface Params {\n table: Table;\n entityName: string;\n attributes: Attributes;\n}\n\nexport const createSystemEntity = (params: Params): Entity<any> => {\n const { entityName, attributes, table } = params;\n return new Entity({\n name: entityName,\n table,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n version: {\n type: \"string\"\n },\n tenant: {\n type: \"string\"\n },\n ...(attributes || {})\n }\n });\n};\n"]}
|
package/definitions/table.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DocumentClient } from "aws-sdk/clients/dynamodb";
|
|
2
2
|
import { Table } from "dynamodb-toolbox";
|
|
3
3
|
interface Params {
|
|
4
|
-
tableName
|
|
4
|
+
tableName?: string;
|
|
5
5
|
documentClient: DocumentClient;
|
|
6
6
|
}
|
|
7
7
|
export declare const createTable: (params: Params) => Table;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["table.ts"],"names":["createTable","params","tableName","documentClient","Table","name","process","env","DB_TABLE","partitionKey","sortKey","DocumentClient"],"mappings":";;;;;;;AACA;;AAOO,MAAMA,WAAW,GAAIC,MAAD,IAA2B;AAClD,QAAM;AAAEC,IAAAA,SAAF;AAAaC,IAAAA;AAAb,MAAgCF,MAAtC;AAEA,SAAO,IAAIG,sBAAJ,CAAU;AACbC,IAAAA,IAAI,EAAEH,SAAS,IAAKI,OAAO,CAACC,GAAR,CAAYC,QADnB;AAEbC,IAAAA,YAAY,EAAE,IAFD;AAGbC,IAAAA,OAAO,EAAE,IAHI;AAIbC,IAAAA,cAAc,EAAER;AAJH,GAAV,CAAP;AAMH,CATM","sourcesContent":["import { DocumentClient } from \"aws-sdk/clients/dynamodb\";\nimport { Table } from \"dynamodb-toolbox\";\n\ninterface Params {\n tableName?: string;\n documentClient: DocumentClient;\n}\n\nexport const createTable = (params: Params): Table => {\n const { tableName, documentClient } = params;\n\n return new Table({\n name: tableName || (process.env.DB_TABLE as string),\n partitionKey: \"PK\",\n sortKey: \"SK\",\n DocumentClient: documentClient\n });\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["tableElasticsearch.ts"],"names":["createElasticsearchTable","params","tableName","documentClient","Table","name","process","env","DB_TABLE_ELASTICSEARCH","partitionKey","sortKey","DocumentClient"],"mappings":";;;;;;;AAAA;;AAQO,MAAMA,wBAAwB,GAAIC,MAAD,IAA2B;AAC/D,QAAM;AAAEC,IAAAA,SAAF;AAAaC,IAAAA;AAAb,MAAgCF,MAAtC;AACA,SAAO,IAAIG,sBAAJ,CAAU;AACbC,IAAAA,IAAI,EAAEH,SAAS,IAAKI,OAAO,CAACC,GAAR,CAAYC,sBADnB;AAEbC,IAAAA,YAAY,EAAE,IAFD;AAGbC,IAAAA,OAAO,EAAE,IAHI;AAIbC,IAAAA,cAAc,EAAER;AAJH,GAAV,CAAP;AAMH,CARM","sourcesContent":["import { Table } from \"dynamodb-toolbox\";\nimport { DocumentClient } from \"aws-sdk/clients/dynamodb\";\n\ninterface Params {\n documentClient: DocumentClient;\n tableName?: string;\n}\n\nexport const createElasticsearchTable = (params: Params): Table => {\n const { tableName, documentClient } = params;\n return new Table({\n name: tableName || (process.env.DB_TABLE_ELASTICSEARCH as string),\n partitionKey: \"PK\",\n sortKey: \"SK\",\n DocumentClient: documentClient\n });\n};\n"]}
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":["reservedFields","isReserved","name","includes","WebinyError","createFormBuilderStorageOperations","params","attributes","table","tableName","esTable","esTableName","documentClient","elasticsearch","plugins","pluginsInput","Object","values","forEach","attrs","keys","PluginsContainer","entities","form","entityName","ENTITIES","FORM","submission","SUBMISSION","system","SYSTEM","settings","SETTINGS","esForm","ES_FORM","esSubmission","ES_SUBMISSION","init","formBuilder","onAfterInstall","subscribe","tenant","upgrade","getTable","getEsTable","getEntities","entity","esEntity"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;AAEA,MAAMA,cAAc,GAAG,CAAC,IAAD,EAAO,IAAP,EAAa,OAAb,EAAsB,MAAtB,EAA8B,MAA9B,EAAsC,QAAtC,EAAgD,SAAhD,EAA2D,SAA3D,CAAvB;;AAEA,MAAMC,UAAU,GAAIC,IAAD,IAAwB;AACvC,MAAIF,cAAc,CAACG,QAAf,CAAwBD,IAAxB,MAAkC,KAAtC,EAA6C;AACzC;AACH;;AACD,QAAM,IAAIE,cAAJ,CAAiB,mBAAkBF,IAAK,mBAAxC,EAA4D,uBAA5D,EAAqF;AACvFA,IAAAA;AADuF,GAArF,CAAN;AAGH,CAPD;;AASO,MAAMG,kCAAuE,GAAGC,MAAM,IAAI;AAC7F,QAAM;AACFC,IAAAA,UADE;AAEFC,IAAAA,KAAK,EAAEC,SAFL;AAGFC,IAAAA,OAAO,EAAEC,WAHP;AAIFC,IAAAA,cAJE;AAKFC,IAAAA,aALE;AAMFC,IAAAA,OAAO,EAAEC;AANP,MAOFT,MAPJ;;AASA,MAAIC,UAAJ,EAAgB;AACZS,IAAAA,MAAM,CAACC,MAAP,CAAcV,UAAd,EAA0BW,OAA1B,CAAkCC,KAAK,IAAI;AACvC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,IAAAA,aAD2B;AAE3BL,IAAAA,KAF2B;AAG3BsC,IAAAA,MAAM,EAAExB,QAAQ,CAACC,IAHU;AAI3BwB,IAAAA,QAAQ,EAAEzB,QAAQ,CAACW,MAJQ;AAK3BnB,IAAAA;AAL2B,GAA5B,CArBP,GA4BO,oDAAkC;AACjCD,IAAAA,aADiC;AAEjCL,IAAAA,KAFiC;AAGjCsC,IAAAA,MAAM,EAAExB,QAAQ,CAACK,UAHgB;AAIjCoB,IAAAA,QAAQ,EAAEzB,QAAQ,CAACa,YAJc;AAKjCrB,IAAAA;AALiC,GAAlC,CA5BP;AAoCH,CA5HM","sourcesContent":["import { FormBuilderStorageOperationsFactory, ENTITIES } from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { createTable } from \"~/definitions/table\";\nimport { createFormEntity } from \"~/definitions/form\";\nimport { createSubmissionEntity } from \"~/definitions/submission\";\nimport { createSystemEntity } from \"~/definitions/system\";\nimport { createSettingsEntity } from \"~/definitions/settings\";\nimport { createSystemStorageOperations } from \"~/operations/system\";\nimport { createSubmissionStorageOperations } from \"~/operations/submission\";\nimport { createSettingsStorageOperations } from \"~/operations/settings\";\nimport { createFormStorageOperations } from \"~/operations/form\";\nimport { createElasticsearchIndex } from \"~/operations/system/createElasticsearchIndex\";\nimport { createElasticsearchTable } from \"~/definitions/tableElasticsearch\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createElasticsearchEntity } from \"~/definitions/elasticsearch\";\nimport submissionElasticsearchFields from \"./operations/submission/elasticsearchFields\";\nimport formElasticsearchFields from \"./operations/form/elasticsearchFields\";\nimport dynamoDbValueFilters from \"@webiny/db-dynamodb/plugins/filters\";\nimport { getElasticsearchOperators } from \"@webiny/api-elasticsearch/operators\";\n\nimport upgrade5160 from \"./upgrades/5.16.0\";\n\nconst reservedFields = [\"PK\", \"SK\", \"index\", \"data\", \"TYPE\", \"__type\", \"GSI1_PK\", \"GSI1_SK\"];\n\nconst isReserved = (name: string): void => {\n if (reservedFields.includes(name) === false) {\n return;\n }\n throw new WebinyError(`Attribute name \"${name}\" is not allowed.`, \"ATTRIBUTE_NOT_ALLOWED\", {\n name\n });\n};\n\nexport const createFormBuilderStorageOperations: FormBuilderStorageOperationsFactory = params => {\n const {\n attributes,\n table: tableName,\n esTable: esTableName,\n documentClient,\n elasticsearch,\n plugins: pluginsInput\n } = params;\n\n if (attributes) {\n Object.values(attributes).forEach(attrs => {\n Object.keys(attrs).forEach(isReserved);\n });\n }\n\n const plugins = new PluginsContainer([\n /**\n * User defined plugins.\n */\n pluginsInput || [],\n /**\n * Elasticsearch field definitions for the submission record.\n */\n submissionElasticsearchFields(),\n /**\n * Elasticsearch field definitions for the form record.\n */\n formElasticsearchFields(),\n /**\n * DynamoDB filter plugins for the where conditions.\n */\n dynamoDbValueFilters(),\n /**\n * Elasticsearch operators.\n */\n getElasticsearchOperators()\n ]);\n\n const table = createTable({\n tableName,\n documentClient\n });\n\n const esTable = createElasticsearchTable({\n tableName: esTableName,\n documentClient\n });\n\n const entities = {\n /**\n * Regular entities.\n */\n form: createFormEntity({\n entityName: ENTITIES.FORM,\n table,\n attributes: attributes ? attributes[ENTITIES.FORM] : {}\n }),\n submission: createSubmissionEntity({\n entityName: ENTITIES.SUBMISSION,\n table,\n attributes: attributes ? attributes[ENTITIES.SUBMISSION] : {}\n }),\n system: createSystemEntity({\n entityName: ENTITIES.SYSTEM,\n table,\n attributes: attributes ? attributes[ENTITIES.SYSTEM] : {}\n }),\n settings: createSettingsEntity({\n entityName: ENTITIES.SETTINGS,\n table,\n attributes: attributes ? attributes[ENTITIES.SETTINGS] : {}\n }),\n /**\n * Elasticsearch entities.\n */\n esForm: createElasticsearchEntity({\n entityName: ENTITIES.ES_FORM,\n table: esTable,\n attributes: attributes ? attributes[ENTITIES.ES_FORM] : {}\n }),\n esSubmission: createElasticsearchEntity({\n entityName: ENTITIES.ES_SUBMISSION,\n table: esTable,\n attributes: attributes ? attributes[ENTITIES.ES_SUBMISSION] : {}\n })\n };\n\n return {\n init: async formBuilder => {\n formBuilder.onAfterInstall.subscribe(async ({ tenant }) => {\n await createElasticsearchIndex({\n elasticsearch,\n tenant\n });\n });\n },\n upgrade: upgrade5160(),\n getTable: () => table,\n getEsTable: () => esTable,\n getEntities: () => entities,\n ...createSystemStorageOperations({\n table,\n entity: entities.system\n }),\n ...createSettingsStorageOperations({\n table,\n entity: entities.settings\n }),\n ...createFormStorageOperations({\n elasticsearch,\n table,\n entity: entities.form,\n esEntity: entities.esForm,\n plugins\n }),\n ...createSubmissionStorageOperations({\n elasticsearch,\n table,\n entity: entities.submission,\n esEntity: entities.esSubmission,\n plugins\n })\n };\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["elasticsearchBody.ts"],"names":["createFormElasticType","createInitialQueryValue","must","term","must_not","should","filter","createElasticsearchQuery","params","plugins","where","initialWhere","fieldPlugins","query","operatorPlugins","byType","ElasticsearchQueryBuilderOperatorPlugin","type","reduce","acc","plugin","getOperator","sharedIndex","process","env","ELASTICSEARCH_SHARED_INDEXES","tenant","push","locale","fields","operators","createElasticsearchBody","limit","initialLimit","sort","initialSort","after","FormElasticsearchFieldPlugin","field","queryModifiers","FormElasticsearchQueryModifierPlugin","modifyQuery","sortModifiers","FormElasticsearchSortModifierPlugin","modifySort","body","constant_score","bool","size","search_after","bodyModifiers","FormElasticsearchBodyModifierPlugin","modifyBody"],"mappings":";;;;;;;;;;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AAEA;;;;;;AAEO,MAAMA,qBAAqB,GAAG,MAAc;AAC/C,SAAO,SAAP;AACH,CAFM;;;;AAIP,MAAMC,uBAAuB,GAAG,MAAoC;AAChE,SAAO;AACHC,IAAAA,IAAI,EAAE;AACF;AACZ;AACA;AACY;AACIC,MAAAA,IAAI,EAAE;AACF,0BAAkBH,qBAAqB;AADrC;AADV,KAJE,CADH;AAWHI,IAAAA,QAAQ,EAAE,EAXP;AAYHC,IA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AA,cAAc,EAAE;AACZxC,QAAAA,MAAM,EAAE;AACJyC,UAAAA,IAAI,oBACGlC,KADH;AADA;AADI;AADb,KADE;AAUTmC,IAAAA,IAAI,EAAEhB,KAAK,GAAG,CAVL;;AAWT;AACR;AACA;AACA;AACA;AACQiB,IAAAA,YAAY,EAAE,2BAAab,KAAb,CAhBL;AAiBTF,IAAAA;AAjBS,GAAb;AAoBA,QAAMgB,aAAa,GAAGzC,OAAO,CAACM,MAAR,CAClBoC,yEAAoClC,IADlB,CAAtB;;AAIA,OAAK,MAAMG,MAAX,IAAqB8B,aAArB,EAAoC;AAChC9B,IAAAA,MAAM,CAACgC,UAAP,CAAkB;AACdP,MAAAA;AADc,KAAlB;AAGH;;AAED,SAAOA,IAAP;AACH,CA1EM","sourcesContent":["import { SearchBody as esSearchBody } from \"elastic-ts\";\nimport { decodeCursor } from \"@webiny/api-elasticsearch/cursors\";\nimport { ElasticsearchBoolQueryConfig } from \"@webiny/api-elasticsearch/types\";\nimport { createSort } from \"@webiny/api-elasticsearch/sort\";\nimport { createLimit } from \"@webiny/api-elasticsearch/limit\";\nimport { ElasticsearchQueryBuilderOperatorPlugin } from \"@webiny/api-elasticsearch/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\nimport { FormElasticsearchFieldPlugin } from \"~/plugins/FormElasticsearchFieldPlugin\";\nimport { FormElasticsearchSortModifierPlugin } from \"~/plugins/FormElasticsearchSortModifierPlugin\";\nimport { FormElasticsearchBodyModifierPlugin } from \"~/plugins/FormElasticsearchBodyModifierPlugin\";\nimport { FormBuilderStorageOperationsListFormsParams } from \"@webiny/api-form-builder/types\";\nimport { FormElasticsearchQueryModifierPlugin } from \"~/plugins/FormElasticsearchQueryModifierPlugin\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { applyWhere } from \"@webiny/api-elasticsearch/where\";\n\nexport const createFormElasticType = (): string => {\n return \"fb.form\";\n};\n\nconst createInitialQueryValue = (): ElasticsearchBoolQueryConfig => {\n return {\n must: [\n /**\n * We add the __type filtering in the initial query because it must be applied.\n */\n {\n term: {\n \"__type.keyword\": createFormElasticType()\n }\n }\n ],\n must_not: [],\n should: [],\n filter: []\n };\n};\n\ninterface CreateElasticsearchQueryParams extends CreateElasticsearchBodyParams {\n fieldPlugins: Record<string, FormElasticsearchFieldPlugin>;\n}\n\nconst createElasticsearchQuery = (params: CreateElasticsearchQueryParams) => {\n const { plugins, where: initialWhere, fieldPlugins } = params;\n const query = createInitialQueryValue();\n /**\n * Be aware that, if having more registered operator plugins of same type, the last one will be used.\n */\n const operatorPlugins = plugins\n .byType<ElasticsearchQueryBuilderOperatorPlugin>(\n ElasticsearchQueryBuilderOperatorPlugin.type\n )\n .reduce((acc, plugin) => {\n acc[plugin.getOperator()] = plugin;\n return acc;\n }, {} as Record<string, ElasticsearchQueryBuilderOperatorPlugin>);\n\n const where: Partial<FormBuilderStorageOperationsListFormsParams[\"where\"]> = {\n ...initialWhere\n };\n /**\n * !!! IMPORTANT !!! There are few specific cases where we hardcode the query conditions.\n *\n * When ES index is shared between tenants, we need to filter records by tenant ID.\n * No need for the tenant filtering otherwise as each index is for single tenant.\n */\n const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === \"true\";\n if (sharedIndex && where.tenant) {\n query.must.push({\n term: {\n \"tenant.keyword\": where.tenant\n }\n });\n }\n /**\n * Remove tenant so it is not applied again later.\n * Possibly tenant is not defined, but just in case, remove it.\n */\n delete where.tenant;\n /**\n * Add the locale to filtering.\n */\n query.must.push({\n term: {\n \"locale.keyword\": where.locale as string\n }\n });\n delete where.locale;\n /**\n * We apply other conditions as they are passed via the where value.\n */\n applyWhere({\n query,\n where,\n fields: fieldPlugins,\n operators: operatorPlugins\n });\n\n return query;\n};\n\ninterface CreateElasticsearchBodyParams {\n plugins: PluginsContainer;\n where: FormBuilderStorageOperationsListFormsParams[\"where\"];\n limit: number;\n after?: string;\n sort: string[];\n}\n\nexport const createElasticsearchBody = (params: CreateElasticsearchBodyParams): esSearchBody => {\n const { plugins, where, limit: initialLimit, sort: initialSort, after } = params;\n\n const fieldPlugins = plugins\n .byType<FormElasticsearchFieldPlugin>(FormElasticsearchFieldPlugin.type)\n .reduce((acc, plugin) => {\n acc[plugin.field] = plugin;\n return acc;\n }, {} as Record<string, FormElasticsearchFieldPlugin>);\n\n const limit = createLimit(initialLimit, 100);\n\n const query = createElasticsearchQuery({\n ...params,\n fieldPlugins\n });\n\n const sort = createSort({\n sort: initialSort,\n fieldPlugins\n });\n\n const queryModifiers = plugins.byType<FormElasticsearchQueryModifierPlugin>(\n FormElasticsearchQueryModifierPlugin.type\n );\n\n for (const plugin of queryModifiers) {\n plugin.modifyQuery({\n query,\n where\n });\n }\n\n const sortModifiers = plugins.byType<FormElasticsearchSortModifierPlugin>(\n FormElasticsearchSortModifierPlugin.type\n );\n\n for (const plugin of sortModifiers) {\n plugin.modifySort({\n sort\n });\n }\n\n const body = {\n query: {\n constant_score: {\n filter: {\n bool: {\n ...query\n }\n }\n }\n },\n size: limit + 1,\n /**\n * Casting as any is required due to search_after is accepting an array of values.\n * Which is correct in some cases. In our case, it is not.\n * https://www.elastic.co/guide/en/elasticsearch/reference/7.13/paginate-search-results.html\n */\n search_after: decodeCursor(after) as any,\n sort\n };\n\n const bodyModifiers = plugins.byType<FormElasticsearchBodyModifierPlugin>(\n FormElasticsearchBodyModifierPlugin.type\n );\n\n for (const plugin of bodyModifiers) {\n plugin.modifyBody({\n body\n });\n }\n\n return body;\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["elasticsearchFields.ts"],"names":["FormElasticsearchFieldPlugin","field","unmappedType","path","ALL"],"mappings":";;;;;;;AAAA;;eAEe,MAAM,CACjB,IAAIA,0DAAJ,CAAiC;AAC7BC,EAAAA,KAAK,EAAE,WADsB;AAE7BC,EAAAA,YAAY,EAAE;AAFe,CAAjC,CADiB,EAKjB,IAAIF,0DAAJ,CAAiC;AAC7BC,EAAAA,KAAK,EAAE,SADsB;AAE7BC,EAAAA,YAAY,EAAE;AAFe,CAAjC,CALiB,EASjB,IAAIF,0DAAJ,CAAiC;AAC7BC,EAAAA,KAAK,EAAE,aADsB;AAE7BC,EAAAA,YAAY,EAAE;AAFe,CAAjC,CATiB,EAajB,IAAIF,0DAAJ,CAAiC;AAC7BC,EAAAA,KAAK,EAAE,SADsB;AAE7BE,EAAAA,IAAI,EAAE;AAFuB,CAAjC,CAbiB,EAiBjB,IAAIH,0DAAJ,CAAiC;AAC7BC,EAAAA,KAAK,EAAE,WADsB;AAE7BE,EAAAA,IAAI,EAAE;AAFuB,CAAjC,CAjBiB;AAqBjB;AACJ;AACA;AACI,IAAIH,0DAAJ,CAAiC;AAC7BC,EAAAA,KAAK,EAAED,2DAA6BI;AADP,CAAjC,CAxBiB,C","sourcesContent":["import { FormElasticsearchFieldPlugin } from \"~/plugins/FormElasticsearchFieldPlugin\";\n\nexport default () => [\n new FormElasticsearchFieldPlugin({\n field: \"createdOn\",\n unmappedType: \"date\"\n }),\n new FormElasticsearchFieldPlugin({\n field: \"savedOn\",\n unmappedType: \"date\"\n }),\n new FormElasticsearchFieldPlugin({\n field: \"publishedOn\",\n unmappedType: \"date\"\n }),\n new FormElasticsearchFieldPlugin({\n field: \"ownedBy\",\n path: \"ownedBy.id\"\n }),\n new FormElasticsearchFieldPlugin({\n field: \"createdBy\",\n path: \"createdBy.id\"\n }),\n /**\n * Always add the ALL fields plugin because of the keyword/path build.\n */\n new FormElasticsearchFieldPlugin({\n field: FormElasticsearchFieldPlugin.ALL\n })\n];\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["fields.ts"],"names":["FormDynamoDbFieldPlugin","field","type"],"mappings":";;;;;;;AAAA;;eAEe,MAAM,CACjB,IAAIA,gDAAJ,CAA4B;AACxBC,EAAAA,KAAK,EAAE,aADiB;AAExBC,EAAAA,IAAI,EAAE;AAFkB,CAA5B,CADiB,C","sourcesContent":["import { FormDynamoDbFieldPlugin } from \"~/plugins/FormDynamoDbFieldPlugin\";\n\nexport default () => [\n new FormDynamoDbFieldPlugin({\n field: \"publishedOn\",\n type: \"date\"\n })\n];\n"]}
|
|
@@ -7,11 +7,11 @@ export declare type DbRecord<T = any> = T & {
|
|
|
7
7
|
SK: string;
|
|
8
8
|
TYPE: string;
|
|
9
9
|
};
|
|
10
|
-
export interface
|
|
10
|
+
export interface CreateFormStorageOperationsParams {
|
|
11
11
|
entity: Entity<any>;
|
|
12
12
|
esEntity: Entity<any>;
|
|
13
13
|
table: Table;
|
|
14
14
|
elasticsearch: Client;
|
|
15
15
|
plugins: PluginsContainer;
|
|
16
16
|
}
|
|
17
|
-
export declare const createFormStorageOperations: (params:
|
|
17
|
+
export declare const createFormStorageOperations: (params: CreateFormStorageOperationsParams) => FormBuilderFormStorageOperations;
|
package/operations/form/index.js
CHANGED
|
@@ -413,7 +413,7 @@ const createFormStorageOperations = params => {
|
|
|
413
413
|
const meta = {
|
|
414
414
|
hasMoreItems,
|
|
415
415
|
totalCount: total.value,
|
|
416
|
-
cursor: items.length > 0 ? (0, _cursors.encodeCursor)(hits[items.length - 1].sort) : null
|
|
416
|
+
cursor: items.length > 0 ? (0, _cursors.encodeCursor)(hits[items.length - 1].sort) || null : null
|
|
417
417
|
};
|
|
418
418
|
return {
|
|
419
419
|
items,
|
|
@@ -466,7 +466,7 @@ const createFormStorageOperations = params => {
|
|
|
466
466
|
fields: formDynamoDbFields
|
|
467
467
|
});
|
|
468
468
|
|
|
469
|
-
if (
|
|
469
|
+
if (!sort || sort.length === 0) {
|
|
470
470
|
return filteredItems;
|
|
471
471
|
}
|
|
472
472
|
|
|
@@ -580,7 +580,7 @@ const createFormStorageOperations = params => {
|
|
|
580
580
|
})));
|
|
581
581
|
} else {
|
|
582
582
|
items.push(entity.deleteBatch({
|
|
583
|
-
PK: createFormPartitionKey(
|
|
583
|
+
PK: createFormPartitionKey(form),
|
|
584
584
|
SK: createLatestPublishedSortKey()
|
|
585
585
|
}));
|
|
586
586
|
}
|
|
@@ -590,7 +590,7 @@ const createFormStorageOperations = params => {
|
|
|
590
590
|
*/
|
|
591
591
|
|
|
592
592
|
|
|
593
|
-
if (isLatest) {
|
|
593
|
+
if (isLatest && previous) {
|
|
594
594
|
items.push(entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, previous), latestKeys), {}, {
|
|
595
595
|
TYPE: createFormLatestType()
|
|
596
596
|
})));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":["getESDataForLatestRevision","form","__type","id","createdOn","savedOn","name","slug","published","publishedOn","version","locked","status","createdBy","ownedBy","tenant","locale","webinyVersion","formId","createFormStorageOperations","params","entity","esEntity","table","plugins","elasticsearch","formDynamoDbFields","createFormPartitionKey","targetId","createRevisionSortKey","value","Number","createLatestSortKey","createLatestPublishedSortKey","createFormType","createFormLatestType","createFormLatestPublishedType","createForm","revisionKeys","PK","SK","latestKeys","items","putBatch","TYPE","ex","WebinyError","message","code","index","configurations","es","put","data","createFormFrom","original","latest","updateForm","latestForm","getForm","where","isLatestForm","push","sortKey","keys","result","get","Item","listForms","sort","limit","after","body","esConfig","query","response","search","hits","total","map","item","_source","hasMoreItems","length","pop","meta","totalCount","cursor","listFormRevisions","initialWhere","queryAllParams","partitionKey","options","beginsWith","undefined","filteredItems","fields","deleteForm","gte","deleteItems","deleteBatch","delete","deleteFormRevision","revisions","previous","latestPublishedForm","find","rev","isLatest","isLatestPublished","esDataItem","previouslyPublishedForm","filter","f","a","b","Date","getTime","shift","publishForm","latestPublishedKeys","esData","unpublishForm","version_not","publishedOn_not","previouslyPublishedRevision"],"mappings":";;;;;;;;;;;AAiBA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAuBA,MAAMA,0BAA0B,GAAIC,IAAD,KAAkC;AACjEC,EAAAA,MAAM,EAAE,+CADyD;AAEjEC,EAAAA,EAAE,EAAEF,IAAI,CAACE,EAFwD;AAGjEC,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FF,EAAE,CAACG,IAAH,IAAW,sBAFT,EAGF;AACI/C,QAAAA,IADJ;AAEIsD,QAAAA,QAFJ;AAGIG,QAAAA,UAHJ;AAIIpB,QAAAA,YAJJ;AAKIG,QAAAA,UALJ;AAMI+E,QAAAA;AANJ,OAHE,CAAN;AAYH;AACD;AACR;AACA;;;AACQ,QAAI,CAACC,MAAL,EAAa;AACT,aAAOxH,IAAP;AACH;;AACD,UAAM;AAAEgD,MAAAA;AAAF,QAAYC,wBAAeC,EAAf,CAAkB;AAChCpC,MAAAA,MAAM,EAAEd,IAAI,CAACc;AADmB,KAAlB,CAAlB;;AAGA,QAAI;AACA,YAAMO,QAAQ,CAAC8B,GAAT,iCACCX,UADD;AAEFQ,QAAAA,KAFE;AAGFL,QAAAA,IAAI,EAAET,oBAAoB,EAHxB;AAIFkB,QAAAA,IAAI,EAAEoE;AAJJ,SAAN;AAMA,aAAOxH,IAAP;AACH,KARD,CAQE,OAAO4C,EAAP,EAAW;AACT,YAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,kDADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,sBAFT,EAGF;AACI/C,QAAAA,IADJ;AAEIsD,QAAAA,QAFJ;AAGIG,QAAAA,UAHJ;AAIIpB,QAAAA,YAJJ;AAKIG,QAAAA,UALJ;AAMI+E,QAAAA;AANJ,OAHE,CAAN;AAYH;AACJ,GAtID;;AAwIA,SAAO;AACHnF,IAAAA,UADG;AAEHiB,IAAAA,cAFG;AAGHG,IAAAA,UAHG;AAIHW,IAAAA,SAJG;AAKHoB,IAAAA,iBALG;AAMH7B,IAAAA,OANG;AAOHsC,IAAAA,UAPG;AAQHK,IAAAA,kBARG;AASHiB,IAAAA,WATG;AAUHG,IAAAA,aAVG;AAWH/F,IAAAA;AAXG,GAAP;AAaH,CAx4BM","sourcesContent":["import {\n FbForm,\n FormBuilderStorageOperationsCreateFormFromParams,\n FormBuilderStorageOperationsCreateFormParams,\n FormBuilderStorageOperationsDeleteFormParams,\n FormBuilderStorageOperationsDeleteFormRevisionParams,\n FormBuilderStorageOperationsGetFormParams,\n FormBuilderStorageOperationsListFormRevisionsParams,\n FormBuilderStorageOperationsListFormRevisionsParamsWhere,\n FormBuilderStorageOperationsListFormsParams,\n FormBuilderStorageOperationsListFormsResponse,\n FormBuilderStorageOperationsPublishFormParams,\n FormBuilderStorageOperationsUnpublishFormParams,\n FormBuilderStorageOperationsUpdateFormParams\n} from \"@webiny/api-form-builder/types\";\nimport { Entity, Table } from \"dynamodb-toolbox\";\nimport { Client } from \"@elastic/elasticsearch\";\nimport { queryAll, QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\nimport WebinyError from \"@webiny/error\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { batchWriteAll } from \"@webiny/db-dynamodb/utils/batchWrite\";\nimport configurations from \"~/configurations\";\nimport { filterItems } from \"@webiny/db-dynamodb/utils/filter\";\nimport fields from \"./fields\";\nimport { sortItems } from \"@webiny/db-dynamodb/utils/sort\";\nimport { parseIdentifier, zeroPad } from \"@webiny/utils\";\nimport { createElasticsearchBody, createFormElasticType } from \"./elasticsearchBody\";\nimport { decodeCursor, encodeCursor } from \"@webiny/api-elasticsearch/cursors\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { FormBuilderFormCreateKeyParams, FormBuilderFormStorageOperations } from \"~/types\";\nimport { ElasticsearchSearchResponse } from \"@webiny/api-elasticsearch/types\";\n\nexport type DbRecord<T = any> = T & {\n PK: string;\n SK: string;\n TYPE: string;\n};\n\nexport interface CreateFormStorageOperationsParams {\n entity: Entity<any>;\n esEntity: Entity<any>;\n table: Table;\n elasticsearch: Client;\n plugins: PluginsContainer;\n}\n\ntype FbFormElastic = Omit<FbForm, \"triggers\" | \"fields\" | \"settings\" | \"layout\" | \"stats\"> & {\n __type: string;\n};\n\nconst getESDataForLatestRevision = (form: FbForm): FbFormElastic => ({\n __type: createFormElasticType(),\n id: form.id,\n createdOn: form.createdOn,\n savedOn: form.savedOn,\n name: form.name,\n slug: form.slug,\n published: form.published,\n publishedOn: form.publishedOn,\n version: form.version,\n locked: form.locked,\n status: form.status,\n createdBy: form.createdBy,\n ownedBy: form.ownedBy,\n tenant: form.tenant,\n locale: form.locale,\n webinyVersion: form.webinyVersion,\n formId: form.formId\n});\n\nexport const createFormStorageOperations = (\n params: CreateFormStorageOperationsParams\n): FormBuilderFormStorageOperations => {\n const { entity, esEntity, table, plugins, elasticsearch } = params;\n\n const formDynamoDbFields = fields();\n\n const createFormPartitionKey = (params: FormBuilderFormCreateKeyParams): string => {\n const { tenant, locale, id: targetId } = params;\n\n const { id } = parseIdentifier(targetId);\n\n return `T#${tenant}#L#${locale}#FB#F#${id}`;\n };\n\n const createRevisionSortKey = (value: string | number | undefined): string => {\n const version =\n typeof value === \"number\" ? Number(value) : (parseIdentifier(value).version as number);\n return `REV#${zeroPad(version)}`;\n };\n\n const createLatestSortKey = (): string => {\n return \"L\";\n };\n\n const createLatestPublishedSortKey = (): string => {\n return \"LP\";\n };\n\n const createFormType = (): string => {\n return \"fb.form\";\n };\n\n const createFormLatestType = (): string => {\n return \"fb.form.latest\";\n };\n\n const createFormLatestPublishedType = (): string => {\n return \"fb.form.latestPublished\";\n };\n\n const createForm = async (\n params: FormBuilderStorageOperationsCreateFormParams\n ): Promise<FbForm> => {\n const { form } = params;\n\n const revisionKeys = {\n PK: createFormPartitionKey(form),\n SK: createRevisionSortKey(form.id)\n };\n const latestKeys = {\n PK: createFormPartitionKey(form),\n SK: createLatestSortKey()\n };\n\n const items = [\n entity.putBatch({\n ...form,\n TYPE: createFormType(),\n ...revisionKeys\n }),\n entity.putBatch({\n ...form,\n TYPE: createFormLatestType(),\n ...latestKeys\n })\n ];\n\n try {\n await batchWriteAll({\n table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not insert form data into regular table.\",\n ex.code || \"CREATE_FORM_ERROR\",\n {\n revisionKeys,\n latestKeys,\n form\n }\n );\n }\n try {\n const { index } = configurations.es({\n tenant: form.tenant\n });\n await esEntity.put({\n index,\n data: getESDataForLatestRevision(form),\n TYPE: createFormType(),\n ...latestKeys\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not insert form data into Elasticsearch table.\",\n ex.code || \"CREATE_FORM_ERROR\",\n {\n latestKeys,\n form\n }\n );\n }\n return form;\n };\n\n const createFormFrom = async (\n params: FormBuilderStorageOperationsCreateFormFromParams\n ): Promise<FbForm> => {\n const { form, original, latest } = params;\n\n const revisionKeys = {\n PK: createFormPartitionKey(form),\n SK: createRevisionSortKey(form.version)\n };\n\n const latestKeys = {\n PK: createFormPartitionKey(form),\n SK: createLatestSortKey()\n };\n\n const items = [\n entity.putBatch({\n ...form,\n ...revisionKeys,\n TYPE: createFormType()\n }),\n entity.putBatch({\n ...form,\n ...latestKeys,\n TYPE: createFormLatestType()\n })\n ];\n\n try {\n await batchWriteAll({\n table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message ||\n \"Could not create form data in the regular table, from existing form.\",\n ex.code || \"CREATE_FORM_FROM_ERROR\",\n {\n revisionKeys,\n latestKeys,\n original,\n form,\n latest\n }\n );\n }\n\n try {\n const { index } = configurations.es({\n tenant: form.tenant\n });\n await esEntity.put({\n index,\n data: getESDataForLatestRevision(form),\n TYPE: createFormLatestType(),\n ...latestKeys\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message ||\n \"Could not create form in the Elasticsearch table, from existing form.\",\n ex.code || \"CREATE_FORM_FROM_ERROR\",\n {\n latestKeys,\n form,\n latest,\n original\n }\n );\n }\n return form;\n };\n\n const updateForm = async (\n params: FormBuilderStorageOperationsUpdateFormParams\n ): Promise<FbForm> => {\n const { form, original } = params;\n\n const revisionKeys = {\n PK: createFormPartitionKey(form),\n SK: createRevisionSortKey(form.id)\n };\n const latestKeys = {\n PK: createFormPartitionKey(form),\n SK: createLatestSortKey()\n };\n\n const { formId, tenant, locale } = form;\n\n const latestForm = await getForm({\n where: {\n formId,\n tenant,\n locale,\n latest: true\n }\n });\n const isLatestForm = latestForm ? latestForm.id === form.id : false;\n\n const items = [\n entity.putBatch({\n ...form,\n TYPE: createFormType(),\n ...revisionKeys\n })\n ];\n if (isLatestForm) {\n items.push(\n entity.putBatch({\n ...form,\n TYPE: createFormLatestType(),\n ...latestKeys\n })\n );\n }\n try {\n await batchWriteAll({\n table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update form data in the regular table.\",\n ex.code || \"UPDATE_FORM_ERROR\",\n {\n revisionKeys,\n latestKeys,\n original,\n form,\n latestForm\n }\n );\n }\n /**\n * No need to go further if its not latest form.\n */\n if (!isLatestForm) {\n return form;\n }\n\n try {\n const { index } = configurations.es({\n tenant: form.tenant\n });\n await esEntity.put({\n index,\n data: getESDataForLatestRevision(form),\n TYPE: createFormLatestType(),\n ...latestKeys\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update form data in the Elasticsearch table.\",\n ex.code || \"UPDATE_FORM_ERROR\",\n {\n latestKeys,\n form,\n latestForm,\n original\n }\n );\n }\n return form;\n };\n\n const getForm = async (\n params: FormBuilderStorageOperationsGetFormParams\n ): Promise<FbForm | null> => {\n const { where } = params;\n const { id, formId, latest, published, version, tenant, locale } = where;\n if (latest && published) {\n throw new WebinyError(\"Cannot have both latest and published params.\");\n }\n let sortKey: string;\n if (latest) {\n sortKey = createLatestSortKey();\n } else if (published && !version) {\n /**\n * Because of the specifics how DynamoDB works, we must not load the published record if version is sent.\n */\n sortKey = createLatestPublishedSortKey();\n } else if (id || version) {\n sortKey = createRevisionSortKey(version || id);\n } else {\n throw new WebinyError(\n \"Missing parameter to create a sort key.\",\n \"MISSING_WHERE_PARAMETER\",\n {\n where\n }\n );\n }\n\n const keys = {\n PK: createFormPartitionKey({\n tenant,\n locale,\n id: (formId || id) as string\n }),\n SK: sortKey\n };\n\n try {\n const result = await entity.get(keys);\n if (!result || !result.Item) {\n return null;\n }\n return cleanupItem(entity, result.Item);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get form by keys.\",\n ex.code || \"GET_FORM_ERROR\",\n {\n keys\n }\n );\n }\n };\n\n const listForms = async (\n params: FormBuilderStorageOperationsListFormsParams\n ): Promise<FormBuilderStorageOperationsListFormsResponse> => {\n const { sort, limit, where, after } = params;\n\n const body = createElasticsearchBody({\n plugins,\n sort,\n limit: limit + 1,\n where,\n after: decodeCursor(after) as any\n });\n\n const esConfig = configurations.es({\n tenant: where.tenant\n });\n\n const query = {\n ...esConfig,\n body\n };\n\n let response: ElasticsearchSearchResponse<FbForm>;\n try {\n response = await elasticsearch.search(query);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could list forms.\",\n ex.code || \"LIST_FORMS_ERROR\",\n {\n where,\n query\n }\n );\n }\n\n const { hits, total } = response.body.hits;\n const items = hits.map(item => item._source);\n\n const hasMoreItems = items.length > limit;\n if (hasMoreItems) {\n /**\n * Remove the last item from results, we don't want to include it.\n */\n items.pop();\n }\n /**\n * Cursor is the `sort` value of the last item in the array.\n * https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after\n */\n\n const meta = {\n hasMoreItems,\n totalCount: total.value,\n cursor: items.length > 0 ? encodeCursor(hits[items.length - 1].sort) || null : null\n };\n\n return {\n items,\n meta\n };\n };\n\n const listFormRevisions = async (\n params: FormBuilderStorageOperationsListFormRevisionsParams\n ): Promise<FbForm[]> => {\n const { where: initialWhere, sort } = params;\n const { id, formId, tenant, locale } = initialWhere;\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createFormPartitionKey({\n tenant,\n locale,\n id: (id || formId) as string\n }),\n options: {\n beginsWith: \"REV#\"\n }\n };\n\n let items: FbForm[] = [];\n try {\n items = await queryAll<FbForm>(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not query forms by given params.\",\n ex.code || \"QUERY_FORMS_ERROR\",\n {\n partitionKey: queryAllParams.partitionKey,\n options: queryAllParams.options\n }\n );\n }\n const where: Partial<FormBuilderStorageOperationsListFormRevisionsParamsWhere> = {\n ...initialWhere,\n id: undefined,\n formId: undefined\n };\n const filteredItems = filterItems({\n plugins,\n items,\n where,\n fields: formDynamoDbFields\n });\n if (!sort || sort.length === 0) {\n return filteredItems;\n }\n return sortItems({\n items: filteredItems,\n sort,\n fields: formDynamoDbFields\n });\n };\n\n const deleteForm = async (\n params: FormBuilderStorageOperationsDeleteFormParams\n ): Promise<FbForm> => {\n const { form } = params;\n let items: any[];\n /**\n * This will find all form and submission records.\n */\n const queryAllParams = {\n entity,\n partitionKey: createFormPartitionKey(form),\n options: {\n gte: \" \"\n }\n };\n try {\n items = await queryAll<DbRecord>(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not query forms and submissions by given params.\",\n ex.code || \"QUERY_FORM_AND_SUBMISSIONS_ERROR\",\n {\n partitionKey: queryAllParams.partitionKey,\n options: queryAllParams.options\n }\n );\n }\n\n const deleteItems = items.map(item => {\n return entity.deleteBatch({\n PK: item.PK,\n SK: item.SK\n });\n });\n try {\n await batchWriteAll({\n table,\n items: deleteItems\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete form and it's submissions.\",\n ex.code || \"DELETE_FORM_AND_SUBMISSIONS_ERROR\"\n );\n }\n\n const latestKeys = {\n PK: createFormPartitionKey(form),\n SK: createLatestSortKey()\n };\n try {\n await esEntity.delete(latestKeys);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete latest form record from Elasticsearch.\",\n ex.code || \"DELETE_FORM_ERROR\",\n {\n latestKeys\n }\n );\n }\n return form;\n };\n /**\n * We need to:\n * - delete current revision\n * - get previously published revision and update the record if it exists or delete if it does not\n * - update latest record if current one is the latest\n */\n const deleteFormRevision = async (\n params: FormBuilderStorageOperationsDeleteFormRevisionParams\n ): Promise<FbForm> => {\n const { form, revisions, previous } = params;\n\n const revisionKeys = {\n PK: createFormPartitionKey(form),\n SK: createRevisionSortKey(form.id)\n };\n\n const latestKeys = {\n PK: createFormPartitionKey(form),\n SK: createLatestSortKey()\n };\n\n const latestForm = revisions[0];\n const latestPublishedForm = revisions.find(rev => rev.published === true);\n\n const isLatest = latestForm ? latestForm.id === form.id : false;\n const isLatestPublished = latestPublishedForm ? latestPublishedForm.id === form.id : false;\n\n const items = [entity.deleteBatch(revisionKeys)];\n let esDataItem = undefined;\n\n if (isLatest || isLatestPublished) {\n /**\n * Sort out the latest published record.\n */\n if (isLatestPublished) {\n const previouslyPublishedForm = revisions\n .filter(f => !!f.publishedOn && f.version !== form.version)\n .sort((a, b) => {\n return (\n new Date(b.publishedOn as string).getTime() -\n new Date(a.publishedOn as string).getTime()\n );\n })\n .shift();\n if (previouslyPublishedForm) {\n items.push(\n entity.putBatch({\n ...previouslyPublishedForm,\n PK: createFormPartitionKey(previouslyPublishedForm),\n SK: createLatestPublishedSortKey(),\n TYPE: createFormLatestPublishedType()\n })\n );\n } else {\n items.push(\n entity.deleteBatch({\n PK: createFormPartitionKey(form),\n SK: createLatestPublishedSortKey()\n })\n );\n }\n }\n /**\n * Sort out the latest record.\n */\n if (isLatest && previous) {\n items.push(\n entity.putBatch({\n ...previous,\n ...latestKeys,\n TYPE: createFormLatestType()\n })\n );\n\n const { index } = configurations.es({\n tenant: previous.tenant\n });\n\n esDataItem = {\n index,\n ...latestKeys,\n data: getESDataForLatestRevision(previous)\n };\n }\n }\n /**\n * Now save the batch data.\n */\n try {\n await batchWriteAll({\n table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete form revision from regular table.\",\n ex.code || \"DELETE_FORM_REVISION_ERROR\",\n {\n form,\n latestForm,\n revisionKeys,\n latestKeys\n }\n );\n }\n /**\n * And then the Elasticsearch data, if any.\n */\n if (!esDataItem) {\n return form;\n }\n try {\n await esEntity.put(esDataItem);\n return form;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete form from to the Elasticsearch table.\",\n ex.code || \"DELETE_FORM_REVISION_ERROR\",\n {\n form,\n latestForm,\n revisionKeys,\n latestKeys\n }\n );\n }\n };\n\n /**\n * We need to save form in:\n * - regular form record\n * - latest published form record\n * - latest form record - if form is latest one\n * - elasticsearch latest form record\n */\n const publishForm = async (\n params: FormBuilderStorageOperationsPublishFormParams\n ): Promise<FbForm> => {\n const { form, original } = params;\n\n const revisionKeys = {\n PK: createFormPartitionKey(form),\n SK: createRevisionSortKey(form.version)\n };\n\n const latestKeys = {\n PK: createFormPartitionKey(form),\n SK: createLatestSortKey()\n };\n\n const latestPublishedKeys = {\n PK: createFormPartitionKey(form),\n SK: createLatestPublishedSortKey()\n };\n\n const { locale, tenant, formId } = form;\n\n const latestForm = await getForm({\n where: {\n formId,\n tenant,\n locale,\n latest: true\n }\n });\n\n const isLatestForm = latestForm ? latestForm.id === form.id : false;\n /**\n * Update revision and latest published records\n */\n const items = [\n entity.putBatch({\n ...form,\n ...revisionKeys,\n TYPE: createFormType()\n }),\n entity.putBatch({\n ...form,\n ...latestPublishedKeys,\n TYPE: createFormLatestPublishedType()\n })\n ];\n /**\n * Update the latest form as well\n */\n if (isLatestForm) {\n items.push(\n entity.putBatch({\n ...form,\n ...latestKeys,\n TYPE: createFormLatestType()\n })\n );\n }\n\n try {\n await batchWriteAll({\n table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not publish form.\",\n ex.code || \"PUBLISH_FORM_ERROR\",\n {\n form,\n original,\n latestForm,\n revisionKeys,\n latestKeys,\n latestPublishedKeys\n }\n );\n }\n if (!isLatestForm) {\n return form;\n }\n const { index } = configurations.es({\n tenant: form.tenant\n });\n const esData = getESDataForLatestRevision(form);\n try {\n await esEntity.put({\n ...latestKeys,\n index,\n TYPE: createFormLatestType(),\n data: esData\n });\n return form;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not publish form to the Elasticsearch.\",\n ex.code || \"PUBLISH_FORM_ERROR\",\n {\n form,\n original,\n latestForm,\n revisionKeys,\n latestKeys,\n latestPublishedKeys\n }\n );\n }\n };\n\n /**\n * We need to:\n * - update form revision record\n * - if latest published (LP) is current form, find the previously published record and update LP if there is some previously published, delete otherwise\n * - if is latest update the Elasticsearch record\n */\n const unpublishForm = async (\n params: FormBuilderStorageOperationsUnpublishFormParams\n ): Promise<FbForm> => {\n const { form, original } = params;\n\n const revisionKeys = {\n PK: createFormPartitionKey(form),\n SK: createRevisionSortKey(form.version)\n };\n\n const latestKeys = {\n PK: createFormPartitionKey(form),\n SK: createLatestSortKey()\n };\n\n const latestPublishedKeys = {\n PK: createFormPartitionKey(form),\n SK: createLatestPublishedSortKey()\n };\n\n const { formId, tenant, locale } = form;\n\n const latestForm = await getForm({\n where: {\n formId,\n tenant,\n locale,\n latest: true\n }\n });\n\n const latestPublishedForm = await getForm({\n where: {\n formId,\n tenant,\n locale,\n published: true\n }\n });\n\n const isLatest = latestForm ? latestForm.id === form.id : false;\n const isLatestPublished = latestPublishedForm ? latestPublishedForm.id === form.id : false;\n\n const items = [\n entity.putBatch({\n ...form,\n ...revisionKeys,\n TYPE: createFormType()\n })\n ];\n let esData: any = undefined;\n if (isLatest) {\n esData = getESDataForLatestRevision(form);\n }\n /**\n * In case previously published revision exists, replace current one with that one.\n * And if it does not, delete the record.\n */\n if (isLatestPublished) {\n const revisions = await listFormRevisions({\n where: {\n formId,\n tenant,\n locale,\n version_not: form.version,\n publishedOn_not: null\n },\n sort: [\"savedOn_DESC\"]\n });\n\n const previouslyPublishedRevision = revisions.shift();\n if (previouslyPublishedRevision) {\n items.push(\n entity.putBatch({\n ...previouslyPublishedRevision,\n ...latestPublishedKeys,\n TYPE: createFormLatestPublishedType()\n })\n );\n } else {\n items.push(entity.deleteBatch(latestPublishedKeys));\n }\n }\n\n try {\n await batchWriteAll({\n table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not unpublish form.\",\n ex.code || \"UNPUBLISH_FORM_ERROR\",\n {\n form,\n original,\n latestForm,\n revisionKeys,\n latestKeys,\n latestPublishedKeys\n }\n );\n }\n /**\n * No need to go further in case of non-existing Elasticsearch data.\n */\n if (!esData) {\n return form;\n }\n const { index } = configurations.es({\n tenant: form.tenant\n });\n try {\n await esEntity.put({\n ...latestKeys,\n index,\n TYPE: createFormLatestType(),\n data: esData\n });\n return form;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not unpublish form from the Elasticsearch.\",\n ex.code || \"UNPUBLISH_FORM_ERROR\",\n {\n form,\n original,\n latestForm,\n revisionKeys,\n latestKeys,\n latestPublishedKeys\n }\n );\n }\n };\n\n return {\n createForm,\n createFormFrom,\n updateForm,\n listForms,\n listFormRevisions,\n getForm,\n deleteForm,\n deleteFormRevision,\n publishForm,\n unpublishForm,\n createFormPartitionKey\n };\n};\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Entity, Table } from "dynamodb-toolbox";
|
|
2
2
|
import { FormBuilderSettingsStorageOperations } from "../../types";
|
|
3
|
-
export interface
|
|
3
|
+
export interface CreateSettingsStorageOperationsParams {
|
|
4
4
|
entity: Entity<any>;
|
|
5
5
|
table: Table;
|
|
6
6
|
}
|
|
7
|
-
export declare const createSettingsStorageOperations: (params:
|
|
7
|
+
export declare const createSettingsStorageOperations: (params: CreateSettingsStorageOperationsParams) => FormBuilderSettingsStorageOperations;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":["createSettingsStorageOperations","params","entity","createSettingsPartitionKey","tenant","locale","createSettingsSortKey","createKeys","PK","SK","createSettings","settings","keys","put","ex","WebinyError","message","code","getSettings","result","get","Item","updateSettings","original","deleteSettings","delete"],"mappings":";;;;;;;;;;;AAYA;;AACA;;;;;;AAOO,MAAMA,+BAA+B,GACxCC,MAD2C,IAEJ;AACvC,QAAM;AAAEC,IAAAA;AAAF,MAAaD,MAAnB;;AAEA,QAAME,0BAA0B,GAAG,CAAC;AAChCC,IAAAA,MADgC;AAEhCC,IAAAA;AAFgC,GAAD,KAGyC;AACxE,WAAQ,KAAID,MAAO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BD;;AAsBA,QAAMU,cAAc,GAAG,MACnBrB,MADmB,IAEC;AACpB,UAAM;AAAEU,MAAAA,QAAF;AAAYY,MAAAA;AAAZ,QAAyBtB,MAA/B;AACA,UAAMW,IAAI,GAAGL,UAAU,CAACI,QAAD,CAAvB;;AAEA,QAAI;AACA,YAAMT,MAAM,CAACW,GAAP,iCACCF,QADD,GAECC,IAFD,EAAN;AAIA,aAAOD,QAAP;AACH,KAND,CAME,OAAOG,EAAP,EAAW;AACT,YAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,qDADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,uBAFT,EAGF;AACIL,QAAAA,IADJ;AAEIW,QAAAA,QAFJ;AAGIZ,QAAAA;AAHJ,OAHE,CAAN;AASH;AACJ,GAvBD;;AAyBA,QAAMa,cAAc,GAAG,MACnBvB,MADmB,IAEH;AAChB,UAAM;AAAEU,MAAAA;AAAF,QAAeV,MAArB;AACA,UAAMW,IAAI,GAAGL,UAAU,CAACI,QAAD,CAAvB;;AACA,QAAI;AACA,YAAMT,MAAM,CAACuB,MAAP,EAAN;AACH,KAFD,CAEE,OAAOX,EAAP,EAAW;AACT,YAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,qDADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,uBAFT,EAGF;AACIL,QAAAA;AADJ,OAHE,CAAN;AAOH;AACJ,GAhBD;;AAkBA,SAAO;AACHF,IAAAA,cADG;AAEHQ,IAAAA,WAFG;AAGHI,IAAAA,cAHG;AAIHE,IAAAA,cAJG;AAKHrB,IAAAA,0BALG;AAMHG,IAAAA;AANG,GAAP;AAQH,CAxHM","sourcesContent":["import {\n FormBuilderStorageOperationsCreateSettingsParams,\n FormBuilderStorageOperationsDeleteSettingsParams,\n FormBuilderStorageOperationsGetSettingsParams,\n FormBuilderStorageOperationsUpdateSettingsParams,\n Settings\n} from \"@webiny/api-form-builder/types\";\nimport { Entity, Table } from \"dynamodb-toolbox\";\nimport {\n FormBuilderSettingsStorageOperations,\n FormBuilderSettingsStorageOperationsCreatePartitionKeyParams\n} from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\n\nexport interface CreateSettingsStorageOperationsParams {\n entity: Entity<any>;\n table: Table;\n}\n\nexport const createSettingsStorageOperations = (\n params: CreateSettingsStorageOperationsParams\n): FormBuilderSettingsStorageOperations => {\n const { entity } = params;\n\n const createSettingsPartitionKey = ({\n tenant,\n locale\n }: FormBuilderSettingsStorageOperationsCreatePartitionKeyParams): string => {\n return `T#${tenant}#L#${locale}#FB#SETTINGS`;\n };\n\n const createSettingsSortKey = (): string => {\n return \"default\";\n };\n\n const createKeys = (params: FormBuilderSettingsStorageOperationsCreatePartitionKeyParams) => {\n return {\n PK: createSettingsPartitionKey(params),\n SK: createSettingsSortKey()\n };\n };\n\n const createSettings = async (\n params: FormBuilderStorageOperationsCreateSettingsParams\n ): Promise<Settings> => {\n const { settings } = params;\n const keys = createKeys(settings);\n\n try {\n await entity.put({\n ...settings,\n ...keys\n });\n return settings;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create the settings record by given keys.\",\n ex.code || \"CREATE_SETTINGS_ERROR\",\n {\n keys,\n settings\n }\n );\n }\n };\n\n const getSettings = async (\n params: FormBuilderStorageOperationsGetSettingsParams\n ): Promise<Settings | null> => {\n const keys = createKeys(params);\n\n try {\n const result = await entity.get(keys);\n if (!result || !result.Item) {\n return null;\n }\n return cleanupItem(entity, result.Item);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get the settings record by given keys.\",\n ex.code || \"LOAD_SETTINGS_ERROR\",\n {\n keys\n }\n );\n }\n };\n\n const updateSettings = async (\n params: FormBuilderStorageOperationsUpdateSettingsParams\n ): Promise<Settings> => {\n const { settings, original } = params;\n const keys = createKeys(settings);\n\n try {\n await entity.put({\n ...settings,\n ...keys\n });\n return settings;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update the settings record by given keys.\",\n ex.code || \"UPDATE_SETTINGS_ERROR\",\n {\n keys,\n original,\n settings\n }\n );\n }\n };\n\n const deleteSettings = async (\n params: FormBuilderStorageOperationsDeleteSettingsParams\n ): Promise<void> => {\n const { settings } = params;\n const keys = createKeys(settings);\n try {\n await entity.delete();\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete the settings record by given keys.\",\n ex.code || \"DELETE_SETTINGS_ERROR\",\n {\n keys\n }\n );\n }\n };\n\n return {\n createSettings,\n getSettings,\n updateSettings,\n deleteSettings,\n createSettingsPartitionKey,\n createSettingsSortKey\n };\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["elasticsearchBody.ts"],"names":["createInitialQueryValue","must","term","must_not","should","filter","createSubmissionElasticType","createElasticsearchQuery","params","plugins","where","initialWhere","fieldPlugins","query","operatorPlugins","byType","ElasticsearchQueryBuilderOperatorPlugin","type","reduce","acc","plugin","getOperator","sharedIndex","process","env","ELASTICSEARCH_SHARED_INDEXES","tenant","push","locale","formId","fields","operators","createElasticsearchBody","limit","initialLimit","sort","initialSort","after","SubmissionElasticsearchFieldPlugin","field","queryModifiers","SubmissionElasticsearchQueryModifierPlugin","modifyQuery","sortModifiers","SubmissionElasticsearchSortModifierPlugin","modifySort","body","constant_score","bool","size","search_after","bodyModifiers","SubmissionElasticsearchBodyModifierPlugin","modifyBody"],"mappings":";;;;;;;;;;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AAEA;;;;;;AAEA,MAAMA,uBAAuB,GAAG,MAAoC;AAChE,SAAO;AACHC,IAAAA,IAAI,EAAE;AACF;AACZ;AACA;AACY;AACIC,MAAAA,IAAI,EAAE;AACF,0BAAkB;AADhB;AADV,KAJE,CADH;AAWHC,IAAAA,QAAQ,EAAE,EAXP;AAYHC,IAAAA,MAAM,EAAE,EAZL;AAaHC,IAAAA,MAAM,EAAE;AAbL,GAAP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CAAtB;;AAIA,OAAK,MAAMG,MAAX,IAAqBuB,aAArB,EAAoC;AAChCvB,IAAAA,MAAM,CAACyB,UAAP,CAAkB;AACdV,MAAAA;AADc,KAAlB;AAGH;;AAED,QAAMW,IAAI,GAAG;AACTjC,IAAAA,KAAK,EAAE;AACHkC,MAAAA,cAAc,EAAE;AACZ1C,QAAAA,MAAM,EAAE;AACJ2C,UAAAA,IAAI,oBACGnC,KADH;AADA;AADI;AADb,KADE;AAUToC,IAAAA,IAAI,EAAEhB,KAAK,GAAG,CAVL;;AAWT;AACR;AACA;AACA;AACA;AACQiB,IAAAA,YAAY,EAAE,2BAAab,KAAb,CAhBL;AAiBTF,IAAAA;AAjBS,GAAb;AAoBA,QAAMgB,aAAa,GAAG1C,OAAO,CAACM,MAAR,CAClBqC,qFAA0CnC,IADxB,CAAtB;;AAIA,OAAK,MAAMG,MAAX,IAAqB+B,aAArB,EAAoC;AAChC/B,IAAAA,MAAM,CAACiC,UAAP,CAAkB;AACdP,MAAAA;AADc,KAAlB;AAGH;;AAED,SAAOA,IAAP;AACH,CA1EM","sourcesContent":["import { SearchBody as esSearchBody } from \"elastic-ts\";\nimport { decodeCursor } from \"@webiny/api-elasticsearch/cursors\";\nimport { ElasticsearchBoolQueryConfig } from \"@webiny/api-elasticsearch/types\";\nimport { createSort } from \"@webiny/api-elasticsearch/sort\";\nimport { createLimit } from \"@webiny/api-elasticsearch/limit\";\nimport { ElasticsearchQueryBuilderOperatorPlugin } from \"@webiny/api-elasticsearch/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\nimport { SubmissionElasticsearchFieldPlugin } from \"~/plugins/SubmissionElasticsearchFieldPlugin\";\nimport { SubmissionElasticsearchSortModifierPlugin } from \"~/plugins/SubmissionElasticsearchSortModifierPlugin\";\nimport { SubmissionElasticsearchBodyModifierPlugin } from \"~/plugins/SubmissionElasticsearchBodyModifierPlugin\";\nimport { FormBuilderStorageOperationsListSubmissionsParams } from \"@webiny/api-form-builder/types\";\nimport { SubmissionElasticsearchQueryModifierPlugin } from \"~/plugins/SubmissionElasticsearchQueryModifierPlugin\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { applyWhere } from \"@webiny/api-elasticsearch/where\";\n\nconst createInitialQueryValue = (): ElasticsearchBoolQueryConfig => {\n return {\n must: [\n /**\n * We add the __type filtering in the initial query because it must be applied.\n */\n {\n term: {\n \"__type.keyword\": \"fb.submission\"\n }\n }\n ],\n must_not: [],\n should: [],\n filter: []\n };\n};\n\nexport const createSubmissionElasticType = (): string => {\n return \"fb.submission\";\n};\n\ninterface CreateElasticsearchQueryParams extends CreateElasticsearchBodyParams {\n fieldPlugins: Record<string, SubmissionElasticsearchFieldPlugin>;\n}\n\nconst createElasticsearchQuery = (params: CreateElasticsearchQueryParams) => {\n const { plugins, where: initialWhere, fieldPlugins } = params;\n const query = createInitialQueryValue();\n /**\n * Be aware that, if having more registered operator plugins of same type, the last one will be used.\n */\n const operatorPlugins = plugins\n .byType<ElasticsearchQueryBuilderOperatorPlugin>(\n ElasticsearchQueryBuilderOperatorPlugin.type\n )\n .reduce((acc, plugin) => {\n acc[plugin.getOperator()] = plugin;\n return acc;\n }, {} as Record<string, ElasticsearchQueryBuilderOperatorPlugin>);\n\n const where: Partial<FormBuilderStorageOperationsListSubmissionsParams[\"where\"]> = {\n ...initialWhere\n };\n /**\n * !!! IMPORTANT !!! There are few specific cases where we hardcode the query conditions.\n *\n * When ES index is shared between tenants, we need to filter records by tenant ID.\n * No need for the tenant filtering otherwise as each index is for single tenant.\n */\n const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === \"true\";\n if (sharedIndex && where.tenant) {\n query.must.push({\n term: {\n \"tenant.keyword\": where.tenant\n }\n });\n }\n /**\n * Remove tenant so it is not applied again later.\n * Possibly tenant is not defined, but just in case, remove it.\n */\n delete where.tenant;\n /**\n * Add the locale to filtering.\n */\n query.must.push({\n term: {\n \"locale.keyword\": where.locale as string\n }\n });\n delete where.locale;\n /**\n * And add the parent (form) to the filtering, if it exists.\n */\n query.must.push({\n term: {\n \"form.parent.keyword\": where.formId as string\n }\n });\n delete where.formId;\n /**\n * We apply other conditions as they are passed via the where value.\n */\n applyWhere({\n query,\n where,\n fields: fieldPlugins,\n operators: operatorPlugins\n });\n\n return query;\n};\n\ninterface CreateElasticsearchBodyParams {\n plugins: PluginsContainer;\n where: FormBuilderStorageOperationsListSubmissionsParams[\"where\"];\n limit: number;\n after?: string;\n sort: string[];\n}\n\nexport const createElasticsearchBody = (params: CreateElasticsearchBodyParams): esSearchBody => {\n const { plugins, where, limit: initialLimit, sort: initialSort, after } = params;\n\n const fieldPlugins = plugins\n .byType<SubmissionElasticsearchFieldPlugin>(SubmissionElasticsearchFieldPlugin.type)\n .reduce((acc, plugin) => {\n acc[plugin.field] = plugin;\n return acc;\n }, {} as Record<string, SubmissionElasticsearchFieldPlugin>);\n\n const limit = createLimit(initialLimit, 100);\n\n const query = createElasticsearchQuery({\n ...params,\n fieldPlugins\n });\n\n const sort = createSort({\n sort: initialSort,\n fieldPlugins\n });\n\n const queryModifiers = plugins.byType<SubmissionElasticsearchQueryModifierPlugin>(\n SubmissionElasticsearchQueryModifierPlugin.type\n );\n\n for (const plugin of queryModifiers) {\n plugin.modifyQuery({\n query,\n where\n });\n }\n\n const sortModifiers = plugins.byType<SubmissionElasticsearchSortModifierPlugin>(\n SubmissionElasticsearchSortModifierPlugin.type\n );\n\n for (const plugin of sortModifiers) {\n plugin.modifySort({\n sort\n });\n }\n\n const body = {\n query: {\n constant_score: {\n filter: {\n bool: {\n ...query\n }\n }\n }\n },\n size: limit + 1,\n /**\n * Casting as any is required due to search_after is accepting an array of values.\n * Which is correct in some cases. In our case, it is not.\n * https://www.elastic.co/guide/en/elasticsearch/reference/7.13/paginate-search-results.html\n */\n search_after: decodeCursor(after) as any,\n sort\n };\n\n const bodyModifiers = plugins.byType<SubmissionElasticsearchBodyModifierPlugin>(\n SubmissionElasticsearchBodyModifierPlugin.type\n );\n\n for (const plugin of bodyModifiers) {\n plugin.modifyBody({\n body\n });\n }\n\n return body;\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["elasticsearchFields.ts"],"names":["SubmissionElasticsearchFieldPlugin","field","path","unmappedType","ALL"],"mappings":";;;;;;;AAAA;;eAEe,MAAM,CACjB,IAAIA,sEAAJ,CAAuC;AACnCC,EAAAA,KAAK,EAAE,QAD4B;AAEnCC,EAAAA,IAAI,EAAE;AAF6B,CAAvC,CADiB,EAKjB,IAAIF,sEAAJ,CAAuC;AACnCC,EAAAA,KAAK,EAAE,SAD4B;AAEnCC,EAAAA,IAAI,EAAE;AAF6B,CAAvC,CALiB,EASjB,IAAIF,sEAAJ,CAAuC;AACnCC,EAAAA,KAAK,EAAE,WAD4B;AAEnCE,EAAAA,YAAY,EAAE;AAFqB,CAAvC,CATiB,EAajB,IAAIH,sEAAJ,CAAuC;AACnCC,EAAAA,KAAK,EAAE,SAD4B;AAEnCE,EAAAA,YAAY,EAAE;AAFqB,CAAvC,CAbiB;AAiBjB;AACJ;AACA;AACI,IAAIH,sEAAJ,CAAuC;AACnCC,EAAAA,KAAK,EAAED,uEAAmCI;AADP,CAAvC,CApBiB,C","sourcesContent":["import { SubmissionElasticsearchFieldPlugin } from \"~/plugins/SubmissionElasticsearchFieldPlugin\";\n\nexport default () => [\n new SubmissionElasticsearchFieldPlugin({\n field: \"parent\",\n path: \"form.parent\"\n }),\n new SubmissionElasticsearchFieldPlugin({\n field: \"ownedBy\",\n path: \"ownedBy.id\"\n }),\n new SubmissionElasticsearchFieldPlugin({\n field: \"createdOn\",\n unmappedType: \"date\"\n }),\n new SubmissionElasticsearchFieldPlugin({\n field: \"savedOn\",\n unmappedType: \"date\"\n }),\n /**\n * Always add the ALL fields plugin because of the keyword/path build.\n */\n new SubmissionElasticsearchFieldPlugin({\n field: SubmissionElasticsearchFieldPlugin.ALL\n })\n];\n"]}
|
|
@@ -2,11 +2,11 @@ import { Entity, Table } from "dynamodb-toolbox";
|
|
|
2
2
|
import { Client } from "@elastic/elasticsearch";
|
|
3
3
|
import { PluginsContainer } from "@webiny/plugins";
|
|
4
4
|
import { FormBuilderSubmissionStorageOperations } from "../../types";
|
|
5
|
-
export interface
|
|
5
|
+
export interface CreateSubmissionStorageOperationsParams {
|
|
6
6
|
entity: Entity<any>;
|
|
7
7
|
esEntity: Entity<any>;
|
|
8
8
|
table: Table;
|
|
9
9
|
elasticsearch: Client;
|
|
10
10
|
plugins: PluginsContainer;
|
|
11
11
|
}
|
|
12
|
-
export declare const createSubmissionStorageOperations: (params:
|
|
12
|
+
export declare const createSubmissionStorageOperations: (params: CreateSubmissionStorageOperationsParams) => FormBuilderSubmissionStorageOperations;
|
|
@@ -182,7 +182,7 @@ const createSubmissionStorageOperations = params => {
|
|
|
182
182
|
where,
|
|
183
183
|
sort
|
|
184
184
|
} = params;
|
|
185
|
-
const items = where.id_in.map(id => {
|
|
185
|
+
const items = (where.id_in || []).map(id => {
|
|
186
186
|
return entity.getBatch({
|
|
187
187
|
PK: createSubmissionPartitionKey(_objectSpread({}, where)),
|
|
188
188
|
SK: createSubmissionSortKey(id)
|
|
@@ -224,7 +224,7 @@ const createSubmissionStorageOperations = params => {
|
|
|
224
224
|
const listSubmissions = async params => {
|
|
225
225
|
const {
|
|
226
226
|
where,
|
|
227
|
-
sort,
|
|
227
|
+
sort = [],
|
|
228
228
|
limit: initialLimit,
|
|
229
229
|
after
|
|
230
230
|
} = params;
|
|
@@ -291,7 +291,7 @@ const createSubmissionStorageOperations = params => {
|
|
|
291
291
|
const meta = {
|
|
292
292
|
hasMoreItems,
|
|
293
293
|
totalCount: total.value,
|
|
294
|
-
cursor: items.length > 0 ? (0, _cursors.encodeCursor)(hits[items.length - 1].sort) : null
|
|
294
|
+
cursor: items.length > 0 ? (0, _cursors.encodeCursor)(hits[items.length - 1].sort) || null : null
|
|
295
295
|
};
|
|
296
296
|
return {
|
|
297
297
|
items,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":["createSubmissionStorageOperations","params","entity","esEntity","table","elasticsearch","plugins","createSubmissionPartitionKey","tenant","locale","formId","id","createSubmissionSortKey","createSubmissionType","createSubmission","submission","form","keys","PK","SK","put","TYPE","ex","WebinyError","message","code","index","configurations","es","data","__type","updateSubmission","original","deleteSubmission","delete","listSubmissionsByIds","where","sort","items","id_in","map","getBatch","results","submissions","filter","Boolean","fields","listSubmissions","limit","initialLimit","after","meta","hasMoreItems","cursor","totalCount","length","body","esConfig","query","response","search","hits","total","item","_source","pop","value","getSubmission","result","get","Item"],"mappings":";;;;;;;;;;;AAWA;;AACA;;AACA;;AACA;;AACA;;AASA;;AACA;;AACA;;AACA;;;;;;AAWO,MAAMA,iCAAiC,GAC1CC,MAD6C,IAEJ;AACzC,QAAM;AAAEC,IAAAA,MAAF;AAAUC,IAAAA,QAAV;AAAoBC,IAAAA,KAApB;AAA2BC,IAAAA,aAA3B;AAA0CC,IAAAA;AAA1C,MAAsDL,MAA5D;;AAEA,QAAMM,4BAA4B,GAC9BN,MADiC,IAEhC;AACD,UAAM;AAAEO,MAAAA,MAAF;AAAUC,MAAAA,MAAV;AAAkBC,MAAAA;AAAlB,QAA6BT,MAAnC;AAEA,UAAM;AAAEU,MAAAA;AAAF,QAAS,4BAAgBD,MAAhB,CAAf;AAEA,WAAQ,KAAIF,MAAO,MAAKC,MAAO,SAAQE,EAAG,EAA1C;AACH,GARD;;AASA,QAAMC,uBAAuB,GAAID,EAAD,IAAgB;AAC5C,WAAQ,MAAKA,EAAG,EAAhB;AACH,GAFD;;AAIA,QAAME,oBAAoB,GAAG,MAAM;AAC/B,WAAO,mBAAP;AACH,GAFD;;AAIA,QAAMC,gBAAgB,GAAG,MACrBb,MADqB,IAEG;AACxB,UAAM;AAAEc,MAAAA,UAAF;AAAcC,MAAAA;AAAd,QAAuBf,MAA7B;AACA,UAAMgB,IAAI,GAAG;AACTC,MAAAA,EAAE,EAAEX,4BAA4B,CAACS,I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AAO,0BAAYpE,MAAZ,EAAoBkE,MAAM,CAACE,IAA3B,CAAP;AACH,KARD,CAQE,OAAOhD,EAAP,EAAW;AACT,YAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,2BADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,sBAFT,EAGF;AACIW,QAAAA,KADJ;AAEInB,QAAAA;AAFJ,OAHE,CAAN;AAQH;AACJ,GA/BD;;AAiCA,SAAO;AACHH,IAAAA,gBADG;AAEHmB,IAAAA,gBAFG;AAGHF,IAAAA,gBAHG;AAIHgB,IAAAA,eAJG;AAKHoB,IAAAA,aALG;AAMH5D,IAAAA,4BANG;AAOHK,IAAAA;AAPG,GAAP;AASH,CAjUM","sourcesContent":["import {\n FbSubmission,\n FormBuilderStorageOperationsCreateSubmissionParams,\n FormBuilderStorageOperationsDeleteSubmissionParams,\n FormBuilderStorageOperationsGetSubmissionParams,\n FormBuilderStorageOperationsListSubmissionsParams,\n FormBuilderStorageOperationsListSubmissionsResponse,\n FormBuilderStorageOperationsUpdateSubmissionParams\n} from \"@webiny/api-form-builder/types\";\nimport { Entity, Table } from \"dynamodb-toolbox\";\nimport { Client } from \"@elastic/elasticsearch\";\nimport WebinyError from \"@webiny/error\";\nimport { batchReadAll } from \"@webiny/db-dynamodb/utils/batchRead\";\nimport { sortItems } from \"@webiny/db-dynamodb/utils/sort\";\nimport { createLimit } from \"@webiny/api-elasticsearch/limit\";\nimport {\n createElasticsearchBody,\n createSubmissionElasticType\n} from \"~/operations/submission/elasticsearchBody\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport {\n FormBuilderSubmissionStorageOperations,\n FormBuilderSubmissionStorageOperationsCreatePartitionKeyParams\n} from \"~/types\";\nimport configurations from \"~/configurations\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { decodeCursor, encodeCursor } from \"@webiny/api-elasticsearch/cursors\";\nimport { ElasticsearchSearchResponse } from \"@webiny/api-elasticsearch/types\";\n\nexport interface CreateSubmissionStorageOperationsParams {\n entity: Entity<any>;\n esEntity: Entity<any>;\n table: Table;\n elasticsearch: Client;\n plugins: PluginsContainer;\n}\n\nexport const createSubmissionStorageOperations = (\n params: CreateSubmissionStorageOperationsParams\n): FormBuilderSubmissionStorageOperations => {\n const { entity, esEntity, table, elasticsearch, plugins } = params;\n\n const createSubmissionPartitionKey = (\n params: FormBuilderSubmissionStorageOperationsCreatePartitionKeyParams\n ) => {\n const { tenant, locale, formId } = params;\n\n const { id } = parseIdentifier(formId);\n\n return `T#${tenant}#L#${locale}#FB#F#${id}`;\n };\n const createSubmissionSortKey = (id: string) => {\n return `FS#${id}`;\n };\n\n const createSubmissionType = () => {\n return \"fb.formSubmission\";\n };\n\n const createSubmission = async (\n params: FormBuilderStorageOperationsCreateSubmissionParams\n ): Promise<FbSubmission> => {\n const { submission, form } = params;\n const keys = {\n PK: createSubmissionPartitionKey(form),\n SK: createSubmissionSortKey(submission.id)\n };\n\n try {\n await entity.put({\n ...submission,\n ...keys,\n TYPE: createSubmissionType()\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create form submission in the DynamoDB.\",\n ex.code || \"UPDATE_FORM_SUBMISSION_ERROR\",\n {\n submission,\n form,\n keys\n }\n );\n }\n\n try {\n const { index } = configurations.es({\n tenant: form.tenant\n });\n await esEntity.put({\n index,\n data: {\n ...submission,\n __type: createSubmissionElasticType()\n },\n TYPE: createSubmissionType(),\n ...keys\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create form submission in the Elasticsearch.\",\n ex.code || \"UPDATE_FORM_SUBMISSION_ERROR\",\n {\n submission,\n form,\n keys\n }\n );\n }\n\n return submission;\n };\n /**\n * We do not save the data in the Elasticsearch because there is no need for that.\n */\n const updateSubmission = async (\n params: FormBuilderStorageOperationsUpdateSubmissionParams\n ): Promise<FbSubmission> => {\n const { submission, form, original } = params;\n const keys = {\n PK: createSubmissionPartitionKey(form),\n SK: createSubmissionSortKey(submission.id)\n };\n\n try {\n await entity.put({\n ...submission,\n ...keys,\n TYPE: createSubmissionType()\n });\n return submission;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update form submission in the DynamoDB.\",\n ex.code || \"UPDATE_FORM_SUBMISSION_ERROR\",\n {\n submission,\n original,\n form,\n keys\n }\n );\n }\n };\n\n const deleteSubmission = async (\n params: FormBuilderStorageOperationsDeleteSubmissionParams\n ): Promise<FbSubmission> => {\n const { submission, form } = params;\n\n const keys = {\n PK: createSubmissionPartitionKey(form),\n SK: createSubmissionSortKey(submission.id)\n };\n\n try {\n await entity.delete(keys);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete form submission from DynamoDB.\",\n ex.code || \"DELETE_FORM_SUBMISSION_ERROR\",\n {\n submission,\n form,\n keys\n }\n );\n }\n\n try {\n await esEntity.delete(keys);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete form submission from Elasticsearch.\",\n ex.code || \"DELETE_FORM_SUBMISSION_ERROR\",\n {\n submission,\n form,\n keys\n }\n );\n }\n\n return submission;\n };\n\n /**\n *\n * We are using this method because it is faster to fetch the exact data from the DynamoDB than Elasticsearch.\n *\n * @internal\n */\n const listSubmissionsByIds = async (\n params: FormBuilderStorageOperationsListSubmissionsParams\n ): Promise<FbSubmission[]> => {\n const { where, sort } = params;\n const items = (where.id_in || []).map(id => {\n return entity.getBatch({\n PK: createSubmissionPartitionKey({\n ...where\n }),\n SK: createSubmissionSortKey(id)\n });\n });\n\n let results: FbSubmission[] = [];\n\n try {\n results = await batchReadAll<FbSubmission>({\n table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not batch read form submissions.\",\n ex.code || \"BATCH_READ_SUBMISSIONS_ERROR\",\n {\n where,\n sort\n }\n );\n }\n /**\n * We need to remove empty results because it is a possibility that batch read returned null for non-existing record.\n */\n const submissions = results.filter(Boolean).map(submission => {\n return cleanupItem(entity, submission);\n }) as FbSubmission[];\n if (!sort) {\n return submissions;\n }\n return sortItems<FbSubmission>({\n items: submissions,\n sort,\n fields: []\n });\n };\n\n const listSubmissions = async (\n params: FormBuilderStorageOperationsListSubmissionsParams\n ): Promise<FormBuilderStorageOperationsListSubmissionsResponse> => {\n const { where, sort = [], limit: initialLimit, after } = params;\n\n if (where.id_in) {\n const items = await listSubmissionsByIds(params);\n\n return {\n items,\n meta: {\n hasMoreItems: false,\n cursor: null,\n totalCount: items.length\n }\n };\n }\n\n const limit = createLimit(initialLimit);\n\n const body = createElasticsearchBody({\n plugins,\n sort,\n limit: limit + 1,\n where,\n after: decodeCursor(after) as any\n });\n\n const esConfig = configurations.es({\n tenant: where.tenant\n });\n\n const query = {\n ...esConfig,\n body\n };\n\n let response: ElasticsearchSearchResponse<FbSubmission>;\n try {\n response = await elasticsearch.search(query);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could list form submissions.\",\n ex.code || \"LIST_SUBMISSIONS_ERROR\",\n {\n where,\n query\n }\n );\n }\n\n const { hits, total } = response.body.hits;\n const items = hits.map(item => item._source);\n\n const hasMoreItems = items.length > limit;\n if (hasMoreItems) {\n /**\n * Remove the last item from results, we don't want to include it.\n */\n items.pop();\n }\n /**\n * Cursor is the `sort` value of the last item in the array.\n * https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after\n */\n const meta = {\n hasMoreItems,\n totalCount: total.value,\n cursor: items.length > 0 ? encodeCursor(hits[items.length - 1].sort) || null : null\n };\n\n return {\n items,\n meta\n };\n };\n\n const getSubmission = async (\n params: FormBuilderStorageOperationsGetSubmissionParams\n ): Promise<FbSubmission | null> => {\n const { where } = params;\n\n const keys = {\n PK: createSubmissionPartitionKey({\n ...where,\n formId: where.formId as string\n }),\n SK: createSubmissionSortKey(where.id)\n };\n\n try {\n const result = await entity.get(keys);\n\n if (!result || !result.Item) {\n return null;\n }\n\n return cleanupItem(entity, result.Item);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not oad submission.\",\n ex.code || \"GET_SUBMISSION_ERROR\",\n {\n where,\n keys\n }\n );\n }\n };\n\n return {\n createSubmission,\n deleteSubmission,\n updateSubmission,\n listSubmissions,\n getSubmission,\n createSubmissionPartitionKey,\n createSubmissionSortKey\n };\n};\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Client } from "@elastic/elasticsearch";
|
|
2
|
-
interface
|
|
2
|
+
interface CreateElasticsearchIndexParams {
|
|
3
3
|
elasticsearch: Client;
|
|
4
4
|
tenant: string;
|
|
5
5
|
}
|
|
6
|
-
export declare const createElasticsearchIndex: (params:
|
|
6
|
+
export declare const createElasticsearchIndex: (params: CreateElasticsearchIndexParams) => Promise<void>;
|
|
7
7
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["createElasticsearchIndex.ts"],"names":["createElasticsearchIndex","params","tenant","elasticsearch","esIndex","configurations","es","body","exists","indices","create","settings","analysis","analyzer","lowercase_analyzer","type","filter","tokenizer","mappings","properties","property","fields","keyword","ignore_above"],"mappings":";;;;;;;;;;;AACA;;;;;;AAOO,MAAMA,wBAAwB,GAAG,MAAOC,MAAP,IAAkD;AACtF,QAAM;AAAEC,IAAAA,MAAF;AAAUC,IAAAA;AAAV,MAA4BF,MAAlC;;AAEA,QAAMG,OAAO,GAAGC,wBAAeC,EAAf,CAAkB;AAC9BJ,IAAAA;AAD8B,GAAlB,CAAhB;;AAIA,QAAM;AAAEK,IAAAA,IAAI,EAAEC;AAAR,MAAmB,MAAML,aAAa,CAACM,OAAd,CAAsBD,MAAtB,CAA6BJ,OAA7B,CAA/B;;AACA,MAAII,MAAJ,EAAY;AACR;AACH;;AACD,QAAML,aAAa,CAACM,OAAd,CAAsBC,MAAtB,iCACCN,OADD;AAEFG,IAAAA,IAAI,EAAE;AACF;AACZ;AACA;AACYI,MAAAA,QAAQ,EAAE;AACNC,QAAAA,QAAQ,EAAE;AACNC,UAAAA,QAAQ,EAAE;AACNC,YAAAA,kBAAkB,EAAE;AAChBC,cAAAA,IAAI,EAAE,QADU;AAEhBC,cAAAA,MAAM,EAAE,CAAC,WAAD,EAAc,MAAd,CAFQ;AAGhBC,cAAAA,SAAS,EAAE;AAHK;AADd;AADJ;AADJ,OAJR;AAeFC,MAAAA,QAAQ,EAAE;AACNC,QAAAA,UAAU,EAAE;AACRC,UAAAA,QAAQ,EAAE;AACNL,YAAAA,IAAI,EAAE,MADA;AAENM,YAAAA,MAAM,EAAE;AACJC,cAAAA,OAAO,EAAE;AACLP,gBAAAA,IAAI,EAAE,SADD;AAELQ,gBAAAA,YAAY,EAAE;AAFT;AADL,aAFF;AAQNV,YAAAA,QAAQ,EAAE;AARJ;AADF;AADN;AAfR;AAFJ,KAAN;AAiCH,CA5CM","sourcesContent":["import { Client } from \"@elastic/elasticsearch\";\nimport configurations from \"~/configurations\";\n\ninterface CreateElasticsearchIndexParams {\n elasticsearch: Client;\n tenant: string;\n}\n\nexport const createElasticsearchIndex = async (params: CreateElasticsearchIndexParams) => {\n const { tenant, elasticsearch } = params;\n\n const esIndex = configurations.es({\n tenant\n });\n\n const { body: exists } = await elasticsearch.indices.exists(esIndex);\n if (exists) {\n return;\n }\n await elasticsearch.indices.create({\n ...esIndex,\n body: {\n /**\n * need this part for sorting to work on text fields\n */\n settings: {\n analysis: {\n analyzer: {\n lowercase_analyzer: {\n type: \"custom\",\n filter: [\"lowercase\", \"trim\"],\n tokenizer: \"keyword\"\n }\n }\n }\n },\n mappings: {\n properties: {\n property: {\n type: \"text\",\n fields: {\n keyword: {\n type: \"keyword\",\n ignore_above: 256\n }\n },\n analyzer: \"lowercase_analyzer\"\n }\n }\n }\n }\n });\n};\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Entity, Table } from "dynamodb-toolbox";
|
|
2
2
|
import { FormBuilderSystemStorageOperations } from "../../types";
|
|
3
|
-
export interface
|
|
3
|
+
export interface CreateSystemStorageOperationsParams {
|
|
4
4
|
entity: Entity<any>;
|
|
5
5
|
table: Table;
|
|
6
6
|
}
|
|
7
|
-
export declare const createSystemStorageOperations: (params:
|
|
7
|
+
export declare const createSystemStorageOperations: (params: CreateSystemStorageOperationsParams) => FormBuilderSystemStorageOperations;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":["createSystemStorageOperations","params","entity","createSystemPartitionKey","tenant","createSystemSortKey","createKeys","PK","SK","createSystem","system","keys","put","ex","WebinyError","message","code","getSystem","result","get","Item","updateSystem","original"],"mappings":";;;;;;;;;;;AAQA;;AACA;;;;;;AAOO,MAAMA,6BAA6B,GACtCC,MADyC,IAEJ;AACrC,QAAM;AAAEC,IAAAA;AAAF,MAAaD,MAAnB;;AAEA,QAAME,wBAAwB,GAAG,CAAC;AAAEC,IAAAA;AAAF,GAAD,KAA2D;AACxF,WAAQ,KAAIA,MAAO,SAAnB;AACH,GAFD;;AAIA,QAAMC,mBAAmB,GAAG,MAAc;AACtC,WAAO,IAAP;AACH,GAFD;;AAIA,QAAMC,UAAU,GAAIL,MAAD,IAA+C;AAC9D,WAAO;AACHM,MAAAA,EAAE,EAAEJ,wBAAwB,CAACF,MAAD,CADzB;AAEHO,MAAAA,EAAE,EAAEH,mBAAmB;AAFpB,KAAP;AAIH,GALD;;AAOA,QAAMI,YAAY,GAAG,MACjBR,MADiB,IAEC;AAClB,UAAM;AAAES,MAAAA;AAAF,QAAaT,MAAnB;AACA,UAAMU,IAAI,GAAGL,UAAU,CAACI,MAAD,CAAvB;;AAEA,QAAI;AACA,YAAMR,MAAM,CAACU,GAAP,iCACCF,MADD,GAECC,IAFD,EAAN;AAIA,aAAOD,MAAP;AACH,KAND,CAME,OAAOG,EAAP,EAAW;AACT,YAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,mDADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,qBAFT,EAGF;AACIL,QAAAA,IADJ;AAEID,QAAAA;AAFJ,OAHE,CAAN;AAQH;AACJ,GAtBD;;AAwBA,QAAMO,SAAS,GAAG,MACdhB,MADc,IAEW;AACzB,UAAMU,IAAI,GAAGL,UAAU,CAACL,MAAD,CAAvB;;AAEA,QAAI;AACA,YAAMiB,MAAM,GAAG,MAAMhB,MAAM,CAACiB,GAAP,CAAWR,IAAX,CAArB;;AACA,UAAI,CAACO,MAAD,IAAW,CAACA,MAAM,CAACE,IAAvB,EAA6B;AACzB,eAAO,IAAP;AACH;;AACD,aAAO,0BAAYlB,MAAZ,EAAoBgB,MAAM,CAACE,IAA3B,CAAP;AACH,KAND,CAME,OAAOP,EAAP,EAAW;AACT,YAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,gDADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,mBAFT,EAGF;AACIL,QAAAA;AADJ,OAHE,CAAN;AAOH;AACJ,GApBD;;AAsBA,QAAMU,YAAY,GAAG,MACjBpB,MADiB,IAEC;AAClB,UAAM;AAAES,MAAAA,MAAF;AAAUY,MAAAA;AAAV,QAAuBrB,MAA7B;AACA,UAAMU,IAAI,GAAGL,UAAU,CAACI,MAAD,CAAvB;;AAEA,QAAI;AACA,YAAMR,MAAM,CAACU,GAAP,iCACCF,MADD,GAECC,IAFD,EAAN;AAIA,aAAOD,MAAP;AACH,KAND,CAME,OAAOG,EAAP,EAAW;AACT,YAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,mDADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,qBAFT,EAGF;AACIL,QAAAA,IADJ;AAEIW,QAAAA,QAFJ;AAGIZ,QAAAA;AAHJ,OAHE,CAAN;AASH;AACJ,GAvBD;;AAyBA,SAAO;AACHD,IAAAA,YADG;AAEHQ,IAAAA,SAFG;AAGHI,IAAAA,YAHG;AAIHlB,IAAAA,wBAJG;AAKHE,IAAAA;AALG,GAAP;AAOH,CAlGM","sourcesContent":["import {\n FormBuilderStorageOperationsCreateSystemParams,\n FormBuilderStorageOperationsGetSystemParams,\n FormBuilderStorageOperationsUpdateSystemParams,\n System\n} from \"@webiny/api-form-builder/types\";\nimport { Entity, Table } from \"dynamodb-toolbox\";\nimport { FormBuilderSystemCreateKeysParams, FormBuilderSystemStorageOperations } from \"~/types\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport WebinyError from \"@webiny/error\";\n\nexport interface CreateSystemStorageOperationsParams {\n entity: Entity<any>;\n table: Table;\n}\n\nexport const createSystemStorageOperations = (\n params: CreateSystemStorageOperationsParams\n): FormBuilderSystemStorageOperations => {\n const { entity } = params;\n\n const createSystemPartitionKey = ({ tenant }: FormBuilderSystemCreateKeysParams): string => {\n return `T#${tenant}#SYSTEM`;\n };\n\n const createSystemSortKey = (): string => {\n return \"FB\";\n };\n\n const createKeys = (params: FormBuilderSystemCreateKeysParams) => {\n return {\n PK: createSystemPartitionKey(params),\n SK: createSystemSortKey()\n };\n };\n\n const createSystem = async (\n params: FormBuilderStorageOperationsCreateSystemParams\n ): Promise<System> => {\n const { system } = params;\n const keys = createKeys(system);\n\n try {\n await entity.put({\n ...system,\n ...keys\n });\n return system;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create the system record by given keys.\",\n ex.code || \"CREATE_SYSTEM_ERROR\",\n {\n keys,\n system\n }\n );\n }\n };\n\n const getSystem = async (\n params: FormBuilderStorageOperationsGetSystemParams\n ): Promise<System | null> => {\n const keys = createKeys(params);\n\n try {\n const result = await entity.get(keys);\n if (!result || !result.Item) {\n return null;\n }\n return cleanupItem(entity, result.Item);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get the system record by given keys.\",\n ex.code || \"LOAD_SYSTEM_ERROR\",\n {\n keys\n }\n );\n }\n };\n\n const updateSystem = async (\n params: FormBuilderStorageOperationsUpdateSystemParams\n ): Promise<System> => {\n const { system, original } = params;\n const keys = createKeys(system);\n\n try {\n await entity.put({\n ...system,\n ...keys\n });\n return system;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update the system record by given keys.\",\n ex.code || \"UPDATE_SYSTEM_ERROR\",\n {\n keys,\n original,\n system\n }\n );\n }\n };\n\n return {\n createSystem,\n getSystem,\n updateSystem,\n createSystemPartitionKey,\n createSystemSortKey\n };\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-form-builder-so-ddb-es",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.25.0-beta.2",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"@webiny/api-form-builder",
|
|
@@ -21,19 +21,19 @@
|
|
|
21
21
|
],
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@babel/runtime": "7.
|
|
24
|
+
"@babel/runtime": "7.17.7",
|
|
25
25
|
"@elastic/elasticsearch": "7.12.0",
|
|
26
|
-
"@webiny/api-elasticsearch": "5.
|
|
27
|
-
"@webiny/api-form-builder": "5.
|
|
28
|
-
"@webiny/api-i18n": "5.
|
|
29
|
-
"@webiny/api-tenancy": "5.
|
|
30
|
-
"@webiny/api-upgrade": "5.
|
|
31
|
-
"@webiny/db-dynamodb": "5.
|
|
32
|
-
"@webiny/error": "5.
|
|
33
|
-
"@webiny/handler": "5.
|
|
34
|
-
"@webiny/handler-aws": "5.
|
|
35
|
-
"@webiny/plugins": "5.
|
|
36
|
-
"@webiny/utils": "5.
|
|
26
|
+
"@webiny/api-elasticsearch": "5.25.0-beta.2",
|
|
27
|
+
"@webiny/api-form-builder": "5.25.0-beta.2",
|
|
28
|
+
"@webiny/api-i18n": "5.25.0-beta.2",
|
|
29
|
+
"@webiny/api-tenancy": "5.25.0-beta.2",
|
|
30
|
+
"@webiny/api-upgrade": "5.25.0-beta.2",
|
|
31
|
+
"@webiny/db-dynamodb": "5.25.0-beta.2",
|
|
32
|
+
"@webiny/error": "5.25.0-beta.2",
|
|
33
|
+
"@webiny/handler": "5.25.0-beta.2",
|
|
34
|
+
"@webiny/handler-aws": "5.25.0-beta.2",
|
|
35
|
+
"@webiny/plugins": "5.25.0-beta.2",
|
|
36
|
+
"@webiny/utils": "5.25.0-beta.2",
|
|
37
37
|
"dynamodb-toolbox": "0.3.5",
|
|
38
38
|
"elastic-ts": "0.7.0"
|
|
39
39
|
},
|
|
@@ -43,17 +43,17 @@
|
|
|
43
43
|
"@babel/preset-env": "^7.16.4",
|
|
44
44
|
"@babel/preset-typescript": "^7.16.0",
|
|
45
45
|
"@shelf/jest-elasticsearch": "^1.0.0",
|
|
46
|
-
"@webiny/api-dynamodb-to-elasticsearch": "^5.
|
|
47
|
-
"@webiny/cli": "^5.
|
|
48
|
-
"@webiny/handler-db": "^5.
|
|
49
|
-
"@webiny/project-utils": "^5.
|
|
46
|
+
"@webiny/api-dynamodb-to-elasticsearch": "^5.25.0-beta.2",
|
|
47
|
+
"@webiny/cli": "^5.25.0-beta.2",
|
|
48
|
+
"@webiny/handler-db": "^5.25.0-beta.2",
|
|
49
|
+
"@webiny/project-utils": "^5.25.0-beta.2",
|
|
50
50
|
"csvtojson": "^2.0.10",
|
|
51
51
|
"jest": "^26.6.3",
|
|
52
52
|
"jest-dynalite": "^3.2.0",
|
|
53
53
|
"jest-environment-node": "^27.2.4",
|
|
54
54
|
"rimraf": "^3.0.2",
|
|
55
55
|
"ttypescript": "^1.5.12",
|
|
56
|
-
"typescript": "
|
|
56
|
+
"typescript": "4.5.5"
|
|
57
57
|
},
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"access": "public",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"build": "yarn webiny run build",
|
|
64
64
|
"watch": "yarn webiny run watch"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "ed2f22976af47aea0b6b5d638f8afdc39951b014"
|
|
67
67
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["FormDynamoDbFieldPlugin.ts"],"names":["FormDynamoDbFieldPlugin","FieldPlugin"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,uBAAN,SAAsCC,wBAAtC,CAAkD;;;8BAA5CD,uB,UACsC,iC","sourcesContent":["import { FieldPlugin } from \"@webiny/db-dynamodb/plugins/definitions/FieldPlugin\";\n\nexport class FormDynamoDbFieldPlugin extends FieldPlugin {\n public static override readonly type: string = \"formBuilder.dynamodb.field.form\";\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["FormElasticsearchBodyModifierPlugin.ts"],"names":["FormElasticsearchBodyModifierPlugin","ElasticsearchBodyModifierPlugin"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,mCAAN,SAAkDC,gEAAlD,CAAkF;;;8BAA5ED,mC,UACsC,8C","sourcesContent":["import { ElasticsearchBodyModifierPlugin } from \"@webiny/api-elasticsearch/plugins/definition/ElasticsearchBodyModifierPlugin\";\n\nexport class FormElasticsearchBodyModifierPlugin extends ElasticsearchBodyModifierPlugin {\n public static override readonly type: string = \"formBuilder.elasticsearch.modifier.body.form\";\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["FormElasticsearchFieldPlugin.ts"],"names":["FormElasticsearchFieldPlugin","ElasticsearchFieldPlugin"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,4BAAN,SAA2CC,kDAA3C,CAAoE;;;8BAA9DD,4B,UACsC,gD","sourcesContent":["import { ElasticsearchFieldPlugin } from \"@webiny/api-elasticsearch/plugins/definition/ElasticsearchFieldPlugin\";\n\nexport class FormElasticsearchFieldPlugin extends ElasticsearchFieldPlugin {\n public static override readonly type: string = \"formBuilder.elasticsearch.fieldDefinition.form\";\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["FormElasticsearchQueryModifierPlugin.ts"],"names":["FormElasticsearchQueryModifierPlugin","ElasticsearchQueryModifierPlugin"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,oCAAN,SAAmDC,kEAAnD,CAAoF;;;8BAA9ED,oC,UACsC,+C","sourcesContent":["import { ElasticsearchQueryModifierPlugin } from \"@webiny/api-elasticsearch/plugins/definition/ElasticsearchQueryModifierPlugin\";\n\nexport class FormElasticsearchQueryModifierPlugin extends ElasticsearchQueryModifierPlugin {\n public static override readonly type: string = \"formBuilder.elasticsearch.modifier.query.form\";\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["FormElasticsearchSortModifierPlugin.ts"],"names":["FormElasticsearchSortModifierPlugin","ElasticsearchSortModifierPlugin"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,mCAAN,SAAkDC,gEAAlD,CAAkF;;;8BAA5ED,mC,UACsC,8C","sourcesContent":["import { ElasticsearchSortModifierPlugin } from \"@webiny/api-elasticsearch/plugins/definition/ElasticsearchSortModifierPlugin\";\n\nexport class FormElasticsearchSortModifierPlugin extends ElasticsearchSortModifierPlugin {\n public static override readonly type: string = \"formBuilder.elasticsearch.modifier.sort.form\";\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["SubmissionElasticsearchBodyModifierPlugin.ts"],"names":["SubmissionElasticsearchBodyModifierPlugin","ElasticsearchBodyModifierPlugin"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,yCAAN,SAAwDC,gEAAxD,CAAwF;;;8BAAlFD,yC,UAEL,oD","sourcesContent":["import { ElasticsearchBodyModifierPlugin } from \"@webiny/api-elasticsearch/plugins/definition/ElasticsearchBodyModifierPlugin\";\n\nexport class SubmissionElasticsearchBodyModifierPlugin extends ElasticsearchBodyModifierPlugin {\n public static override readonly type: string =\n \"formBuilder.elasticsearch.modifier.body.submission\";\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["SubmissionElasticsearchFieldPlugin.ts"],"names":["SubmissionElasticsearchFieldPlugin","ElasticsearchFieldPlugin"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,kCAAN,SAAiDC,kDAAjD,CAA0E;;;8BAApED,kC,UAEL,sD","sourcesContent":["import { ElasticsearchFieldPlugin } from \"@webiny/api-elasticsearch/plugins/definition/ElasticsearchFieldPlugin\";\n\nexport class SubmissionElasticsearchFieldPlugin extends ElasticsearchFieldPlugin {\n public static override readonly type: string =\n \"formBuilder.elasticsearch.fieldDefinition.submission\";\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["SubmissionElasticsearchQueryModifierPlugin.ts"],"names":["SubmissionElasticsearchQueryModifierPlugin","ElasticsearchQueryModifierPlugin"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,0CAAN,SAAyDC,kEAAzD,CAA0F;;;8BAApFD,0C,UAEL,qD","sourcesContent":["import { ElasticsearchQueryModifierPlugin } from \"@webiny/api-elasticsearch/plugins/definition/ElasticsearchQueryModifierPlugin\";\n\nexport class SubmissionElasticsearchQueryModifierPlugin extends ElasticsearchQueryModifierPlugin {\n public static override readonly type: string =\n \"formBuilder.elasticsearch.modifier.query.submission\";\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["SubmissionElasticsearchSortModifierPlugin.ts"],"names":["SubmissionElasticsearchSortModifierPlugin","ElasticsearchSortModifierPlugin"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,yCAAN,SAAwDC,gEAAxD,CAAwF;;;8BAAlFD,yC,UAEL,oD","sourcesContent":["import { ElasticsearchSortModifierPlugin } from \"@webiny/api-elasticsearch/plugins/definition/ElasticsearchSortModifierPlugin\";\n\nexport class SubmissionElasticsearchSortModifierPlugin extends ElasticsearchSortModifierPlugin {\n public static override readonly type: string =\n \"formBuilder.elasticsearch.modifier.sort.submission\";\n}\n"]}
|
package/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["types.ts"],"names":["ENTITIES"],"mappings":";;;;;;IAqBYA,Q;;;WAAAA,Q;AAAAA,EAAAA,Q;AAAAA,EAAAA,Q;AAAAA,EAAAA,Q;AAAAA,EAAAA,Q;AAAAA,EAAAA,Q;AAAAA,EAAAA,Q;GAAAA,Q,wBAAAA,Q","sourcesContent":["import {\n FormBuilderStorageOperations as BaseFormBuilderStorageOperations,\n FormBuilderSystemStorageOperations as BaseFormBuilderSystemStorageOperations,\n FormBuilderSubmissionStorageOperations as BaseFormBuilderSubmissionStorageOperations,\n FormBuilderSettingsStorageOperations as BaseFormBuilderSettingsStorageOperations,\n FormBuilderFormStorageOperations as BaseFormBuilderFormStorageOperations\n} from \"@webiny/api-form-builder/types\";\nimport { DocumentClient } from \"aws-sdk/clients/dynamodb\";\nimport { Table, Entity } from \"dynamodb-toolbox\";\nimport { DynamoDBTypes } from \"dynamodb-toolbox/dist/classes/Table\";\nimport {\n EntityAttributeConfig,\n EntityCompositeAttributes\n} from \"dynamodb-toolbox/dist/classes/Entity\";\nimport { Client } from \"@elastic/elasticsearch\";\nimport { Plugin } from \"@webiny/plugins\";\n\nexport type AttributeDefinition = DynamoDBTypes | EntityAttributeConfig | EntityCompositeAttributes;\n\nexport type Attributes = Record<string, AttributeDefinition>;\n\nexport enum ENTITIES {\n FORM = \"FormBuilderForm\",\n ES_FORM = \"FormBuilderFormEs\",\n SUBMISSION = \"FormBuilderSubmission\",\n ES_SUBMISSION = \"FormBuilderSubmissionEs\",\n SYSTEM = \"FormBuilderSystem\",\n SETTINGS = \"FormBuilderSettings\"\n}\n\nexport interface FormBuilderStorageOperationsFactoryParams {\n documentClient: DocumentClient;\n elasticsearch: Client;\n table?: string;\n esTable?: string;\n attributes?: Record<ENTITIES, Attributes>;\n plugins?: Plugin[];\n}\n\nexport interface FormBuilderSystemCreateKeysParams {\n tenant: string;\n}\n\nexport interface FormBuilderSystemStorageOperations extends BaseFormBuilderSystemStorageOperations {\n createSystemPartitionKey: (params: FormBuilderSystemCreateKeysParams) => string;\n createSystemSortKey: () => string;\n}\n\nexport interface FormBuilderFormCreateKeyParams {\n id: string;\n tenant: string;\n locale: string;\n}\n\nexport interface FormBuilderFormStorageOperations extends BaseFormBuilderFormStorageOperations {\n createFormPartitionKey: (params: FormBuilderFormCreateKeyParams) => string;\n}\n\nexport interface FormBuilderSubmissionStorageOperationsCreatePartitionKeyParams {\n tenant: string;\n locale: string;\n formId: string;\n}\n\nexport interface FormBuilderSubmissionStorageOperations\n extends BaseFormBuilderSubmissionStorageOperations {\n createSubmissionPartitionKey: (\n params: FormBuilderSubmissionStorageOperationsCreatePartitionKeyParams\n ) => string;\n createSubmissionSortKey: (id: string) => string;\n}\n\nexport interface FormBuilderSettingsStorageOperationsCreatePartitionKeyParams {\n tenant: string;\n locale: string;\n}\n\nexport interface FormBuilderSettingsStorageOperations\n extends BaseFormBuilderSettingsStorageOperations {\n createSettingsPartitionKey: (\n params: FormBuilderSettingsStorageOperationsCreatePartitionKeyParams\n ) => string;\n createSettingsSortKey: () => string;\n}\n\nexport type Entities = \"form\" | \"esForm\" | \"submission\" | \"esSubmission\" | \"system\" | \"settings\";\n\nexport interface FormBuilderStorageOperations\n extends BaseFormBuilderStorageOperations,\n FormBuilderSettingsStorageOperations,\n FormBuilderSubmissionStorageOperations,\n FormBuilderFormStorageOperations,\n FormBuilderSystemStorageOperations {\n getTable(): Table;\n getEsTable(): Table;\n getEntities(): Record<Entities, Entity<any>>;\n}\n\nexport interface FormBuilderStorageOperationsFactory {\n (params: FormBuilderStorageOperationsFactoryParams): FormBuilderStorageOperations;\n}\n"]}
|
package/upgrades/5.16.0/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":["upgradeForms","params","storageOperations","tenant","locale","webinyVersion","forms","items","listForms","where","latest","id","code","after","limit","sort","ex","console","log","message","length","entity","getEntities","form","formId","formRecords","partitionKey","createFormPartitionKey","record","PK","SK","push","putBatch","table","WebinyError","error","type","app","version","apply","context","tenancy","getCurrentTenant","i18nContent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K,WAAR,CACrB3C,iBADL;AAGA,YAAMF,YAAY,CAAC;AACfE,QAAAA,iBADe;AAEfC,QAAAA,MAFe;AAGfC,QAAAA,MAHe;AAIfC,QAAAA,aAAa,EAAEmC,OAAO,CAACM;AAJR,OAAD,CAAlB;AAMH;AAhBE,GAAP;AAkBH,C","sourcesContent":["/**\n * Not used anymore.\n */\n// @ts-nocheck\nimport { UpgradePlugin } from \"@webiny/api-upgrade/types\";\nimport { FormBuilderContext } from \"@webiny/api-form-builder/types\";\nimport { FormBuilderStorageOperations } from \"~/types\";\nimport { queryAll } from \"@webiny/db-dynamodb/utils/query\";\nimport { I18NLocale } from \"@webiny/api-i18n/types\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { batchWriteAll } from \"@webiny/db-dynamodb/utils/batchWrite\";\nimport WebinyError from \"@webiny/error\";\n\ninterface Params {\n storageOperations: FormBuilderStorageOperations;\n tenant: Tenant;\n locale: I18NLocale;\n webinyVersion: string;\n}\n\nconst upgradeForms = async (params: Params): Promise<void> => {\n const { storageOperations, tenant, locale, webinyVersion } = params;\n /**\n * We need all of the forms from the database.\n * We are getting them from the Elasticsearch because there is no general PK for the forms.\n */\n let forms: any[] = [];\n try {\n const { items } = await storageOperations.listForms({\n where: {\n latest: true,\n tenant: tenant.id,\n locale: locale.code\n },\n after: null,\n limit: 10000,\n sort: [\"createdOn_DESC\"]\n });\n forms = items;\n } catch (ex) {\n console.log(\"Upgrade forms 5.16.0\");\n console.log(ex.message);\n return;\n }\n\n if (forms.length === 0) {\n return;\n }\n\n const entity = storageOperations.getEntities().form;\n const items: any[] = [];\n /**\n * ## Regular DynamoDB table.\n * We need to get all the records from all of the forms.\n * Unfortunately, we need to query in a loop to be able to get those forms.\n */\n for (const form of forms) {\n const { id: formId } = parseIdentifier(form.id);\n\n const formRecords: any[] = await queryAll({\n entity,\n partitionKey: storageOperations.createFormPartitionKey({\n id: form.id,\n tenant: tenant.id,\n locale: locale.code\n })\n });\n\n for (const record of formRecords) {\n /**\n * Checks for \"just in case\".\n */\n if (!record || !record.PK || !record.SK) {\n continue;\n }\n items.push(\n entity.putBatch({\n ...record,\n formId,\n webinyVersion\n })\n );\n }\n }\n /**\n * And finally write all the records to the database again.\n */\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\"Could not update all form records.\", \"UPGRADE_FORM_RECORDS_ERROR\", {\n error: ex\n });\n }\n /**\n * ## Elasticsearch DynamoDB table.\n */\n};\n/**\n * This upgrade adds:\n * - formId (first part of the id) and webinyVersion to the form records\n */\nexport default (): UpgradePlugin<FormBuilderContext> => {\n return {\n type: \"api-upgrade\",\n app: \"form-builder\",\n version: \"5.16.0\",\n apply: async context => {\n const tenant = context.tenancy.getCurrentTenant();\n const locale = context.i18nContent.getCurrentLocale();\n const storageOperations = context.formBuilder\n .storageOperations as FormBuilderStorageOperations;\n\n await upgradeForms({\n storageOperations,\n tenant,\n locale,\n webinyVersion: context.WEBINY_VERSION\n });\n }\n };\n};\n"]}
|