@kaspernj/api-maker 1.0.247 → 1.0.248

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/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  ]
17
17
  },
18
18
  "name": "@kaspernj/api-maker",
19
- "version": "1.0.247",
19
+ "version": "1.0.248",
20
20
  "type": "module",
21
21
  "description": "",
22
22
  "main": "index.js",
@@ -6,6 +6,7 @@ import Deserializer from "./deserializer.mjs"
6
6
  import {dig, digg} from "diggerize"
7
7
  import FormDataObjectizer from "form-data-objectizer"
8
8
  import Serializer from "./serializer.mjs"
9
+ import SessionStatusUpdater from "./session-status-updater.mjs"
9
10
  import ValidationError from "./validation-error.mjs"
10
11
  import {ValidationErrors} from "./validation-errors.mjs"
11
12
 
@@ -89,6 +90,27 @@ export default class ApiMakerCommandsPool {
89
90
  return Object.keys(this.pool)
90
91
  }
91
92
 
93
+ async sendRequest ({commandSubmitData, url}) {
94
+ let response
95
+
96
+ for (let i = 0; i < 3; i++) {
97
+ if (commandSubmitData.getFilesCount() > 0) {
98
+ response = await Api.requestLocal({path: url, method: "POST", rawData: commandSubmitData.getFormData()})
99
+ } else {
100
+ response = await Api.requestLocal({path: url, method: "POST", data: commandSubmitData.getJsonData()})
101
+ }
102
+
103
+ if (response.success === false && response.type == "invalid_authenticity_token") {
104
+ console.error("invalid_authenticity_token - try again")
105
+ await SessionStatusUpdater.current().updateSessionStatus()
106
+ continue;
107
+ }
108
+
109
+ console.error(`Request succeeded after ${i} tries`)
110
+ return response
111
+ }
112
+ }
113
+
92
114
  async flush () {
93
115
  if (this.commandsCount() == 0) {
94
116
  return
@@ -111,14 +133,7 @@ export default class ApiMakerCommandsPool {
111
133
 
112
134
  const commandSubmitData = new CommandSubmitData(submitData)
113
135
  const url = "/api_maker/commands"
114
-
115
- let response
116
-
117
- if (commandSubmitData.getFilesCount() > 0) {
118
- response = await Api.requestLocal({path: url, method: "POST", rawData: commandSubmitData.getFormData()})
119
- } else {
120
- response = await Api.requestLocal({path: url, method: "POST", data: commandSubmitData.getJsonData()})
121
- }
136
+ const response = await this.sendRequest({commandSubmitData, url})
122
137
 
123
138
  for (const commandId in response.responses) {
124
139
  const commandResponse = response.responses[commandId]
@@ -1,6 +1,6 @@
1
- import BaseError from "./base-error.mjs"
1
+ import CustomError from "./custom-error.mjs"
2
2
 
3
- class DestroyError extends BaseError {}
3
+ class DestroyError extends CustomError {}
4
4
 
5
5
  DestroyError.apiMakerType = "DestroyError"
6
6
 
@@ -206,17 +206,9 @@ class ApiMakerTable extends React.PureComponent {
206
206
  const {abilities, modelClass} = this.props
207
207
  const ownAbilities = []
208
208
 
209
- if (this.props.destroyEnabled) {
210
- ownAbilities.push("destroy")
211
- }
212
-
213
- if (this.props.editModelPath) {
214
- ownAbilities.push("edit")
215
- }
216
-
217
- if (this.props.viewModelPath) {
218
- ownAbilities.push("show")
219
- }
209
+ if (this.props.destroyEnabled) ownAbilities.push("destroy")
210
+ if (this.props.editModelPath) ownAbilities.push("edit")
211
+ if (this.props.viewModelPath) ownAbilities.push("show")
220
212
 
221
213
  if (ownAbilities.length > 0) {
222
214
  const modelClassName = digg(modelClass.modelClassData(), "name")