@natlibfi/melinda-rest-api-commons 2.3.0-alpha.7 → 2.3.1-alpha.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/dist/utils.js CHANGED
@@ -89,7 +89,7 @@ function createRecordResponseItem({
89
89
  recordMetadata,
90
90
  id
91
91
  }) {
92
- const recordResponseStatusAndMessage = getRecordResponseStatusAndMessage(responseStatus, responsePayload);
92
+ const recordResponseStatusAndMessage = getRecordResponseStatusAndMessage(responseStatus, responsePayload, id);
93
93
  const recordResponseItem = {
94
94
  databaseId: id || '000000000',
95
95
  recordMetadata: responsePayload.recordMetadata || recordMetadata || undefined,
@@ -99,88 +99,89 @@ function createRecordResponseItem({
99
99
  } // eslint-disable-next-line max-statements
100
100
 
101
101
 
102
- function getRecordResponseStatusAndMessage(responseStatus, responsePayload) {
102
+ function getRecordResponseStatusAndMessage(responseStatus, responsePayload, id) {
103
103
  logger.debug(`Response status: ${responseStatus} responsePayload: ${JSON.stringify(responsePayload)}`);
104
104
  const responseStatusName = _httpStatus.default[`${responseStatus}_NAME`];
105
105
  logger.debug(`Response status name: ${responseStatusName}`);
106
106
  const message = getMessageFromResponsePayload(responsePayload);
107
+ const {
108
+ ids
109
+ } = responsePayload || [];
107
110
  logger.debug(`Response message: ${message}`); // Non-http statuses
108
111
 
109
112
  if (['UPDATED', 'CREATED', 'INVALID', 'ERROR', 'SKIPPED'].includes(responseStatus)) {
110
113
  return {
111
- status: responseStatus,
114
+ recordStatus: responseStatus,
112
115
  message
113
116
  };
114
117
  }
115
118
 
116
119
  if (['UNKNOWN'].includes(responseStatus)) {
117
- const possibleIds = responsePayload.ids || [];
118
120
  return {
119
- status: responseStatus,
121
+ recordStatus: responseStatus,
120
122
  message,
121
- possibleIds
123
+ ids
122
124
  };
123
125
  } // Duplicates and other CONFLICT statuses
124
126
 
125
127
 
126
128
  if ([_httpStatus.default.CONFLICT, 'CONFLICT'].includes(responseStatus)) {
127
129
  if (/^Duplicates in database/u.test(message)) {
128
- const duplicateIds = responsePayload.ids || [];
129
130
  return {
130
- status: 'DUPLICATE',
131
+ recordStatus: 'DUPLICATE',
131
132
  message,
132
- duplicateIds
133
+ ids
133
134
  };
134
135
  }
135
136
 
136
137
  if (/^MatchValidation for all/u.test(message)) {
137
- const duplicateIds = responsePayload.ids || [];
138
138
  return {
139
- status: 'CONFLICT',
139
+ recordStatus: 'CONFLICT',
140
140
  message,
141
- duplicateIds
141
+ ids
142
142
  };
143
- }
143
+ } // Use ids only if there are more than one id or the id in payload does not match databaseId
144
144
 
145
- const conflictIds = responsePayload.ids || [];
146
145
 
147
- if (conflictIds.length > 0) {
146
+ if (ids.length > 1 || ids[0] !== id) {
148
147
  return {
149
- status: 'CONFLICT',
148
+ recordStatus: 'CONFLICT',
150
149
  message,
151
- conflictIds
150
+ ids
152
151
  };
153
152
  }
154
153
 
155
154
  return {
156
- status: 'CONFLICT',
155
+ recordStatus: 'CONFLICT',
157
156
  message
158
157
  };
159
158
  }
160
159
 
161
160
  if ([_httpStatus.default.UNPROCESSABLE_ENTITY, 'UNPROCESSABLE_ENTITY'].includes(responseStatus)) {
162
- const unprocessableIds = responsePayload.ids || [];
163
- const response = unprocessableIds.length > 0 ? {
164
- status: 'UNPROCESSABLE_ENTITY',
165
- message,
166
- unprocessableIds
167
- } : {
168
- status: 'UNPROCESSABLE_ENTITY',
161
+ if (ids.length > 1 || ids[0] !== id) {
162
+ return {
163
+ recordStatus: 'UNPROCESSABLE_ENTITY',
164
+ message,
165
+ ids
166
+ };
167
+ }
168
+
169
+ return {
170
+ recordStatus: 'UNPROCESSABLE_ENTITY',
169
171
  message
170
172
  };
171
- return response;
172
173
  }
173
174
 
174
175
  if ([_httpStatus.default.NOT_FOUND, 'NOT_FOUND'].includes(responseStatus)) {
175
176
  return {
176
- status: 'NOT_FOUND',
177
+ recordStatus: 'NOT_FOUND',
177
178
  message
178
179
  };
179
180
  } // Otherwise
180
181
 
181
182
 
182
183
  return {
183
- status: 'ERROR',
184
+ recordStatus: 'ERROR',
184
185
  message
185
186
  };
186
187
  }
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":["logger","createLogger","logError","err","ApiError","error","JSON","stringify","stack","undefined","createImportJobState","operation","state","queryImportJobState","IMPORT_JOB_STATE","Error","OPERATIONS","importJobStateWithOperation","importJobStateForQuery","createRecordResponseItem","responsePayload","responseStatus","recordMetadata","id","recordResponseStatusAndMessage","getRecordResponseStatusAndMessage","recordResponseItem","databaseId","debug","responseStatusName","httpStatus","message","getMessageFromResponsePayload","includes","status","possibleIds","ids","CONFLICT","test","duplicateIds","conflictIds","length","UNPROCESSABLE_ENTITY","unprocessableIds","response","NOT_FOUND","String","addRecordResponseItem","correlationId","mongoOperator","pushMessages","messages","messageField"],"sources":["../src/utils.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2021 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\nimport {Error as ApiError} from '@natlibfi/melinda-commons';\nimport {IMPORT_JOB_STATE, OPERATIONS} from './constants';\nimport httpStatus from 'http-status';\n\nconst logger = createLogger();\n\nexport function logError(err) {\n if (err instanceof ApiError) {\n logger.error(JSON.stringify(err));\n return;\n }\n\n if (err === 'SIGINT') {\n logger.error(err);\n return;\n }\n\n logger.error(err.stack === undefined ? err : err.stack);\n}\n\nexport function createImportJobState(operation, state, queryImportJobState = false) {\n if (!(state in IMPORT_JOB_STATE)) {\n throw new Error('Invalid IMPORT_JOB_STATE');\n }\n\n if (!(operation in OPERATIONS)) {\n throw new Error('Invalid operation');\n }\n\n if (queryImportJobState) {\n const importJobStateWithOperation = `importJobState.${operation}`;\n const importJobStateForQuery = {[importJobStateWithOperation]: state};\n\n return importJobStateForQuery;\n }\n\n return {[operation]: state};\n}\n\nexport function createRecordResponseItem({responsePayload, responseStatus, recordMetadata, id}) {\n const recordResponseStatusAndMessage = getRecordResponseStatusAndMessage(responseStatus, responsePayload);\n const recordResponseItem = {\n databaseId: id || '000000000',\n recordMetadata: responsePayload.recordMetadata || recordMetadata || undefined,\n ...recordResponseStatusAndMessage\n };\n return recordResponseItem;\n}\n\n// eslint-disable-next-line max-statements\nfunction getRecordResponseStatusAndMessage(responseStatus, responsePayload) {\n\n logger.debug(`Response status: ${responseStatus} responsePayload: ${JSON.stringify(responsePayload)}`);\n const responseStatusName = httpStatus[`${responseStatus}_NAME`];\n logger.debug(`Response status name: ${responseStatusName}`);\n\n const message = getMessageFromResponsePayload(responsePayload);\n\n logger.debug(`Response message: ${message}`);\n\n // Non-http statuses\n if (['UPDATED', 'CREATED', 'INVALID', 'ERROR', 'SKIPPED'].includes(responseStatus)) {\n return {status: responseStatus, message};\n }\n\n if (['UNKNOWN'].includes(responseStatus)) {\n const possibleIds = responsePayload.ids || [];\n return {status: responseStatus, message, possibleIds};\n }\n\n // Duplicates and other CONFLICT statuses\n if ([httpStatus.CONFLICT, 'CONFLICT'].includes(responseStatus)) {\n if ((/^Duplicates in database/u).test(message)) {\n const duplicateIds = responsePayload.ids || [];\n return {status: 'DUPLICATE', message, duplicateIds};\n }\n if ((/^MatchValidation for all/u).test(message)) {\n const duplicateIds = responsePayload.ids || [];\n return {status: 'CONFLICT', message, duplicateIds};\n }\n const conflictIds = responsePayload.ids || [];\n if (conflictIds.length > 0) {\n return {status: 'CONFLICT', message, conflictIds};\n }\n return {status: 'CONFLICT', message};\n }\n\n if ([httpStatus.UNPROCESSABLE_ENTITY, 'UNPROCESSABLE_ENTITY'].includes(responseStatus)) {\n const unprocessableIds = responsePayload.ids || [];\n const response = unprocessableIds.length > 0 ? {status: 'UNPROCESSABLE_ENTITY', message, unprocessableIds} : {status: 'UNPROCESSABLE_ENTITY', message};\n return response;\n }\n\n if ([httpStatus.NOT_FOUND, 'NOT_FOUND'].includes(responseStatus)) {\n return {status: 'NOT_FOUND', message};\n }\n\n // Otherwise\n return {status: 'ERROR', message};\n}\n\nfunction getMessageFromResponsePayload(responsePayload) {\n if (responsePayload.message) {\n return responsePayload.message;\n }\n if (typeof responsePayload === 'string' || responsePayload instanceof String) {\n return responsePayload;\n }\n return '';\n}\n\nexport async function addRecordResponseItem({recordResponseItem, correlationId, mongoOperator}) {\n await mongoOperator.pushMessages({correlationId, messages: [recordResponseItem], messageField: 'records'});\n return true;\n}\n\n"],"mappings":";;;;;;;;;;AA4BA;;AACA;;AACA;;AACA;;;;AA/BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAOA,MAAMA,MAAM,GAAG,IAAAC,mCAAA,GAAf;;AAEO,SAASC,QAAT,CAAkBC,GAAlB,EAAuB;EAC5B,IAAIA,GAAG,YAAYC,qBAAnB,EAA6B;IAC3BJ,MAAM,CAACK,KAAP,CAAaC,IAAI,CAACC,SAAL,CAAeJ,GAAf,CAAb;IACA;EACD;;EAED,IAAIA,GAAG,KAAK,QAAZ,EAAsB;IACpBH,MAAM,CAACK,KAAP,CAAaF,GAAb;IACA;EACD;;EAEDH,MAAM,CAACK,KAAP,CAAaF,GAAG,CAACK,KAAJ,KAAcC,SAAd,GAA0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names":["logger","createLogger","logError","err","ApiError","error","JSON","stringify","stack","undefined","createImportJobState","operation","state","queryImportJobState","IMPORT_JOB_STATE","Error","OPERATIONS","importJobStateWithOperation","importJobStateForQuery","createRecordResponseItem","responsePayload","responseStatus","recordMetadata","id","recordResponseStatusAndMessage","getRecordResponseStatusAndMessage","recordResponseItem","databaseId","debug","responseStatusName","httpStatus","message","getMessageFromResponsePayload","ids","includes","recordStatus","CONFLICT","test","length","UNPROCESSABLE_ENTITY","NOT_FOUND","String","addRecordResponseItem","correlationId","mongoOperator","pushMessages","messages","messageField"],"sources":["../src/utils.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2021 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\nimport {Error as ApiError} from '@natlibfi/melinda-commons';\nimport {IMPORT_JOB_STATE, OPERATIONS} from './constants';\nimport httpStatus from 'http-status';\n\nconst logger = createLogger();\n\nexport function logError(err) {\n if (err instanceof ApiError) {\n logger.error(JSON.stringify(err));\n return;\n }\n\n if (err === 'SIGINT') {\n logger.error(err);\n return;\n }\n\n logger.error(err.stack === undefined ? err : err.stack);\n}\n\nexport function createImportJobState(operation, state, queryImportJobState = false) {\n if (!(state in IMPORT_JOB_STATE)) {\n throw new Error('Invalid IMPORT_JOB_STATE');\n }\n\n if (!(operation in OPERATIONS)) {\n throw new Error('Invalid operation');\n }\n\n if (queryImportJobState) {\n const importJobStateWithOperation = `importJobState.${operation}`;\n const importJobStateForQuery = {[importJobStateWithOperation]: state};\n\n return importJobStateForQuery;\n }\n\n return {[operation]: state};\n}\n\nexport function createRecordResponseItem({responsePayload, responseStatus, recordMetadata, id}) {\n const recordResponseStatusAndMessage = getRecordResponseStatusAndMessage(responseStatus, responsePayload, id);\n const recordResponseItem = {\n databaseId: id || '000000000',\n recordMetadata: responsePayload.recordMetadata || recordMetadata || undefined,\n ...recordResponseStatusAndMessage\n };\n return recordResponseItem;\n}\n\n// eslint-disable-next-line max-statements\nfunction getRecordResponseStatusAndMessage(responseStatus, responsePayload, id) {\n\n logger.debug(`Response status: ${responseStatus} responsePayload: ${JSON.stringify(responsePayload)}`);\n const responseStatusName = httpStatus[`${responseStatus}_NAME`];\n logger.debug(`Response status name: ${responseStatusName}`);\n\n const message = getMessageFromResponsePayload(responsePayload);\n const {ids} = responsePayload || [];\n\n logger.debug(`Response message: ${message}`);\n\n // Non-http statuses\n if (['UPDATED', 'CREATED', 'INVALID', 'ERROR', 'SKIPPED'].includes(responseStatus)) {\n return {recordStatus: responseStatus, message};\n }\n\n if (['UNKNOWN'].includes(responseStatus)) {\n return {recordStatus: responseStatus, message, ids};\n }\n\n // Duplicates and other CONFLICT statuses\n if ([httpStatus.CONFLICT, 'CONFLICT'].includes(responseStatus)) {\n if ((/^Duplicates in database/u).test(message)) {\n return {recordStatus: 'DUPLICATE', message, ids};\n }\n if ((/^MatchValidation for all/u).test(message)) {\n return {recordStatus: 'CONFLICT', message, ids};\n }\n\n // Use ids only if there are more than one id or the id in payload does not match databaseId\n if (ids.length > 1 || ids[0] !== id) {\n return {recordStatus: 'CONFLICT', message, ids};\n }\n return {recordStatus: 'CONFLICT', message};\n }\n\n if ([httpStatus.UNPROCESSABLE_ENTITY, 'UNPROCESSABLE_ENTITY'].includes(responseStatus)) {\n if (ids.length > 1 || ids[0] !== id) {\n return {recordStatus: 'UNPROCESSABLE_ENTITY', message, ids};\n }\n return {recordStatus: 'UNPROCESSABLE_ENTITY', message};\n }\n\n if ([httpStatus.NOT_FOUND, 'NOT_FOUND'].includes(responseStatus)) {\n return {recordStatus: 'NOT_FOUND', message};\n }\n\n // Otherwise\n return {recordStatus: 'ERROR', message};\n}\n\nfunction getMessageFromResponsePayload(responsePayload) {\n if (responsePayload.message) {\n return responsePayload.message;\n }\n if (typeof responsePayload === 'string' || responsePayload instanceof String) {\n return responsePayload;\n }\n return '';\n}\n\nexport async function addRecordResponseItem({recordResponseItem, correlationId, mongoOperator}) {\n await mongoOperator.pushMessages({correlationId, messages: [recordResponseItem], messageField: 'records'});\n return true;\n}\n\n"],"mappings":";;;;;;;;;;AA4BA;;AACA;;AACA;;AACA;;;;AA/BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAOA,MAAMA,MAAM,GAAG,IAAAC,mCAAA,GAAf;;AAEO,SAASC,QAAT,CAAkBC,GAAlB,EAAuB;EAC5B,IAAIA,GAAG,YAAYC,qBAAnB,EAA6B;IAC3BJ,MAAM,CAACK,KAAP,CAAaC,IAAI,CAACC,SAAL,CAAeJ,GAAf,CAAb;IACA;EACD;;EAED,IAAIA,GAAG,KAAK,QAAZ,EAAsB;IACpBH,MAAM,CAACK,KAAP,CAAaF,GAAb;IACA;EACD;;EAEDH,MAAM,CAACK,KAAP,CAAaF,GAAG,CAACK,KAAJ,KAAcC,SAAd,GAA0BN,GAA1B,GAAgCA,GAAG,CAACK,KAAjD;AACD;;AAEM,SAASE,oBAAT,CAA8BC,SAA9B,EAAyCC,KAAzC,EAAgDC,mBAAmB,GAAG,KAAtE,EAA6E;EAClF,IAAI,EAAED,KAAK,IAAIE,2BAAX,CAAJ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AAqC;MACnC,OAAO;QAACY,YAAY,EAAE,sBAAf;QAAuCJ,OAAvC;QAAgDE;MAAhD,CAAP;IACD;;IACD,OAAO;MAACE,YAAY,EAAE,sBAAf;MAAuCJ;IAAvC,CAAP;EACD;;EAED,IAAI,CAACD,mBAAA,CAAWU,SAAZ,EAAuB,WAAvB,EAAoCN,QAApC,CAA6Cb,cAA7C,CAAJ,EAAkE;IAChE,OAAO;MAACc,YAAY,EAAE,WAAf;MAA4BJ;IAA5B,CAAP;EACD,CA7C6E,CA+C9E;;;EACA,OAAO;IAACI,YAAY,EAAE,OAAf;IAAwBJ;EAAxB,CAAP;AACD;;AAED,SAASC,6BAAT,CAAuCZ,eAAvC,EAAwD;EACtD,IAAIA,eAAe,CAACW,OAApB,EAA6B;IAC3B,OAAOX,eAAe,CAACW,OAAvB;EACD;;EACD,IAAI,OAAOX,eAAP,KAA2B,QAA3B,IAAuCA,eAAe,YAAYqB,MAAtE,EAA8E;IAC5E,OAAOrB,eAAP;EACD;;EACD,OAAO,EAAP;AACD;;AAEM,eAAesB,qBAAf,CAAqC;EAAChB,kBAAD;EAAqBiB,aAArB;EAAoCC;AAApC,CAArC,EAAyF;EAC9F,MAAMA,aAAa,CAACC,YAAd,CAA2B;IAACF,aAAD;IAAgBG,QAAQ,EAAE,CAACpB,kBAAD,CAA1B;IAAgDqB,YAAY,EAAE;EAA9D,CAA3B,CAAN;EACA,OAAO,IAAP;AACD"}
package/package.json CHANGED
@@ -14,8 +14,8 @@
14
14
  "url": "git@github.com:natlibfi/melinda-rest-api-commons.git"
15
15
  },
16
16
  "license": "AGPL-3.0+",
17
- "version": "2.3.0-alpha.7",
18
- "main": "./dist/index.js",
17
+ "version": "2.3.1-alpha.2",
18
+ "main": "dist/index.js",
19
19
  "engines": {
20
20
  "node": ">=14"
21
21
  },