@natlibfi/melinda-rest-api-commons 2.3.0-alpha.7 → 2.3.1-alpha.1

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,7 +99,7 @@ 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}`);
@@ -108,7 +108,7 @@ function getRecordResponseStatusAndMessage(responseStatus, responsePayload) {
108
108
 
109
109
  if (['UPDATED', 'CREATED', 'INVALID', 'ERROR', 'SKIPPED'].includes(responseStatus)) {
110
110
  return {
111
- status: responseStatus,
111
+ recordStatus: responseStatus,
112
112
  message
113
113
  };
114
114
  }
@@ -116,7 +116,7 @@ function getRecordResponseStatusAndMessage(responseStatus, responsePayload) {
116
116
  if (['UNKNOWN'].includes(responseStatus)) {
117
117
  const possibleIds = responsePayload.ids || [];
118
118
  return {
119
- status: responseStatus,
119
+ recordStatus: responseStatus,
120
120
  message,
121
121
  possibleIds
122
122
  };
@@ -127,7 +127,7 @@ function getRecordResponseStatusAndMessage(responseStatus, responsePayload) {
127
127
  if (/^Duplicates in database/u.test(message)) {
128
128
  const duplicateIds = responsePayload.ids || [];
129
129
  return {
130
- status: 'DUPLICATE',
130
+ recordStatus: 'DUPLICATE',
131
131
  message,
132
132
  duplicateIds
133
133
  };
@@ -136,24 +136,24 @@ function getRecordResponseStatusAndMessage(responseStatus, responsePayload) {
136
136
  if (/^MatchValidation for all/u.test(message)) {
137
137
  const duplicateIds = responsePayload.ids || [];
138
138
  return {
139
- status: 'CONFLICT',
139
+ recordStatus: 'CONFLICT',
140
140
  message,
141
141
  duplicateIds
142
142
  };
143
143
  }
144
144
 
145
- const conflictIds = responsePayload.ids || [];
145
+ const conflictIds = responsePayload.ids || []; // use conflictIds only if there are more than one id or the id in payload does not match databaseId
146
146
 
147
- if (conflictIds.length > 0) {
147
+ if (conflictIds.length > 1 || conflictIds[0] !== id) {
148
148
  return {
149
- status: 'CONFLICT',
149
+ recordStatus: 'CONFLICT',
150
150
  message,
151
151
  conflictIds
152
152
  };
153
153
  }
154
154
 
155
155
  return {
156
- status: 'CONFLICT',
156
+ recordStatus: 'CONFLICT',
157
157
  message
158
158
  };
159
159
  }
@@ -161,11 +161,11 @@ function getRecordResponseStatusAndMessage(responseStatus, responsePayload) {
161
161
  if ([_httpStatus.default.UNPROCESSABLE_ENTITY, 'UNPROCESSABLE_ENTITY'].includes(responseStatus)) {
162
162
  const unprocessableIds = responsePayload.ids || [];
163
163
  const response = unprocessableIds.length > 0 ? {
164
- status: 'UNPROCESSABLE_ENTITY',
164
+ recordStatus: 'UNPROCESSABLE_ENTITY',
165
165
  message,
166
166
  unprocessableIds
167
167
  } : {
168
- status: 'UNPROCESSABLE_ENTITY',
168
+ recordStatus: 'UNPROCESSABLE_ENTITY',
169
169
  message
170
170
  };
171
171
  return response;
@@ -173,14 +173,14 @@ function getRecordResponseStatusAndMessage(responseStatus, responsePayload) {
173
173
 
174
174
  if ([_httpStatus.default.NOT_FOUND, 'NOT_FOUND'].includes(responseStatus)) {
175
175
  return {
176
- status: 'NOT_FOUND',
176
+ recordStatus: 'NOT_FOUND',
177
177
  message
178
178
  };
179
179
  } // Otherwise
180
180
 
181
181
 
182
182
  return {
183
- status: 'ERROR',
183
+ recordStatus: 'ERROR',
184
184
  message
185
185
  };
186
186
  }
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,CA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OAAO,IAAP;AACD"}
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","recordStatus","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, 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\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 const possibleIds = responsePayload.ids || [];\n return {recordStatus: 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 {recordStatus: 'DUPLICATE', message, duplicateIds};\n }\n if ((/^MatchValidation for all/u).test(message)) {\n const duplicateIds = responsePayload.ids || [];\n return {recordStatus: 'CONFLICT', message, duplicateIds};\n }\n const conflictIds = responsePayload.ids || [];\n // use conflictIds only if there are more than one id or the id in payload does not match databaseId\n if (conflictIds.length > 1 || conflictIds[0] !== id) {\n return {recordStatus: 'CONFLICT', message, conflictIds};\n }\n return {recordStatus: 'CONFLICT', message};\n }\n\n if ([httpStatus.UNPROCESSABLE_ENTITY, 'UNPROCESSABLE_ENTITY'].includes(responseStatus)) {\n const unprocessableIds = responsePayload.ids || [];\n const response = unprocessableIds.length > 0 ? {recordStatus: 'UNPROCESSABLE_ENTITY', message, unprocessableIds} : {recordStatus: 'UNPROCESSABLE_ENTITY', message};\n return response;\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,C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QAAQ,EAAE,CAACzB,kBAAD,CAA1B;IAAgD0B,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.1",
18
+ "main": "dist/index.js",
19
19
  "engines": {
20
20
  "node": ">=14"
21
21
  },