@cloudize/sdk-core 25.1.3 → 25.1.5

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.
@@ -11,6 +11,10 @@ export type ResourceObjectMetadata = {
11
11
  searchScore?: number;
12
12
  distance?: number;
13
13
  };
14
+ export type ResourceObjectSaveOptions = {
15
+ onRewritePostPayload?: (payload: any) => any;
16
+ onRewritePatchPayload?: (payload: any) => any;
17
+ };
14
18
  export default class ResourceObject implements IResourceObject {
15
19
  private _container;
16
20
  private _id;
@@ -35,7 +39,7 @@ export default class ResourceObject implements IResourceObject {
35
39
  private HasHeader;
36
40
  private InsertResource;
37
41
  private UpdateResource;
38
- Save(): Promise<void>;
42
+ Save(options?: ResourceObjectSaveOptions): Promise<void>;
39
43
  toJSON(): any;
40
44
  get type(): string;
41
45
  get id(): string;
@@ -239,12 +239,15 @@ class ResourceObject {
239
239
  }
240
240
  return hasHeader;
241
241
  }
242
- InsertResource() {
242
+ InsertResource(options) {
243
243
  return __awaiter(this, void 0, void 0, function* () {
244
244
  const queryUri = this._container.uri;
245
245
  const queryHeaders = this._container.GetHeaders('INSERT');
246
246
  const queryOptions = {};
247
- const payload = this.GetInsertPayload();
247
+ let payload = this.GetInsertPayload();
248
+ if ((options === null || options === void 0 ? void 0 : options.onRewritePostPayload) && (0, json_1.isDefinedAndNotNull)(options.onRewritePostPayload) && options.onRewritePostPayload instanceof Function) {
249
+ payload = options === null || options === void 0 ? void 0 : options.onRewritePostPayload(payload);
250
+ }
248
251
  const response = yield this._container.restClient.Post(queryUri, payload, queryHeaders, queryOptions);
249
252
  if (!this.HasHeader(response.headers, 'location')) {
250
253
  throw new __1.SDKException('INVALID-LOCATION', 'The save operation was unable to retrieve the location '
@@ -256,25 +259,39 @@ class ResourceObject {
256
259
  }
257
260
  this.id = this.GetHeaderValue(response.headers, 'x-api-resource-id');
258
261
  this._uri = this.GetHeaderValue(response.headers, 'location');
262
+ if ((0, json_1.isDefined)(response.data) && (0, json_1.isObject)(response.data)) {
263
+ if ((0, json_1.hasProperty)(response.data, 'data')) {
264
+ if ((0, json_1.isObject)(response.data.data)) {
265
+ const resourceData = response.data.data;
266
+ if ((0, json_1.hasProperty)(resourceData, 'type') && (0, json_1.isString)(resourceData.type) && resourceData.type === this.type
267
+ && (0, json_1.hasProperty)(resourceData, 'id') && (0, json_1.isString)(resourceData.id) && resourceData.id === this.id) {
268
+ this.LoadData(resourceData);
269
+ }
270
+ }
271
+ }
272
+ }
259
273
  this._mode = ResourceObjectMode.ExistingDocument;
260
274
  });
261
275
  }
262
- UpdateResource() {
276
+ UpdateResource(options) {
263
277
  return __awaiter(this, void 0, void 0, function* () {
264
278
  const queryUri = this.uri;
265
279
  const queryHeaders = this._container.GetHeaders('UPDATE');
266
280
  const queryOptions = {};
267
- const payload = this.GetUpdatePayload();
281
+ let payload = this.GetUpdatePayload();
282
+ if ((options === null || options === void 0 ? void 0 : options.onRewritePatchPayload) && (0, json_1.isDefinedAndNotNull)(options.onRewritePatchPayload) && options.onRewritePatchPayload instanceof Function) {
283
+ payload = options === null || options === void 0 ? void 0 : options.onRewritePatchPayload(payload);
284
+ }
268
285
  yield this._container.restClient.Patch(queryUri, payload, queryHeaders, queryOptions);
269
286
  });
270
287
  }
271
- Save() {
288
+ Save(options) {
272
289
  return __awaiter(this, void 0, void 0, function* () {
273
290
  if (this._mode === ResourceObjectMode.NewDocument) {
274
- yield this.InsertResource();
291
+ yield this.InsertResource(options);
275
292
  }
276
293
  else {
277
- yield this.UpdateResource();
294
+ yield this.UpdateResource(options);
278
295
  }
279
296
  if ((0, json_1.isDefined)(this.attributes)) {
280
297
  this.shadowAttributes.LoadData(this.attributes, __1.ResourceObjectAttributesLoadType.Replace);
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  ],
14
14
  "description": "Cloudize SDK Core",
15
15
  "license": "MIT",
16
- "version": "25.1.3",
16
+ "version": "25.1.5",
17
17
  "main": "lib/index.js",
18
18
  "types": "lib/index.d.ts",
19
19
  "scripts": {
@@ -39,9 +39,9 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/jest": "^30.0.0",
42
- "@types/node": "^24.10.9",
43
- "@typescript-eslint/eslint-plugin": "^8.54.0",
44
- "@typescript-eslint/parser": "^8.54.0",
42
+ "@types/node": "^24.10.13",
43
+ "@typescript-eslint/eslint-plugin": "^8.56.1",
44
+ "@typescript-eslint/parser": "^8.56.1",
45
45
  "date-and-time": "^3.6.0",
46
46
  "eslint": "^8.57.1",
47
47
  "eslint-config-airbnb-base": "^15.0.0",