@chaibuilder/pages 0.4.0 → 0.4.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/server.js CHANGED
@@ -32,11 +32,10 @@ class L {
32
32
  email: a,
33
33
  password: e
34
34
  }) {
35
- const t = await this.backend.handleUsersAction({
35
+ return await this.backend.handleUsersAction({
36
36
  action: "LOGIN",
37
37
  data: { email: a, password: e }
38
38
  });
39
- return t.error ? { error: t.error } : t;
40
39
  }
41
40
  async logout() {
42
41
  await this.backend.handleUsersAction({
@@ -294,10 +293,10 @@ class M {
294
293
  return await this.backend.handleUpload(a, e);
295
294
  }
296
295
  async handle(a, e) {
297
- var n, r, o, c, l, k;
296
+ var t, r, o, c, l, k;
298
297
  switch (a.action) {
299
298
  case "REFRESH_TOKEN":
300
- return (n = this.chaiUsers) == null ? void 0 : n.refreshToken(
299
+ return (t = this.chaiUsers) == null ? void 0 : t.refreshToken(
301
300
  a.data
302
301
  );
303
302
  case "LOGIN":
@@ -352,23 +351,23 @@ class M {
352
351
  );
353
352
  return s ? s.search ? await s.search(a.data.query) : this.backend.handleAction(a, e) : { error: "Page type not found" };
354
353
  }
355
- const t = await this.backend.handleAction(a, e);
356
- return this.emit(a.action, t), t;
354
+ const n = await this.backend.handleAction(a, e);
355
+ return this.emit(a.action, n), n;
357
356
  }
358
357
  emit(a, e) {
359
358
  var r, o, c;
360
359
  if (!["CREATE_PAGE", "UPDATE_PAGE", "DELETE_PAGE"].includes(a)) return;
361
- const t = p(e, "page");
362
- if (!t) return;
363
- const n = h(t.pageType);
364
- if (n)
360
+ const n = p(e, "page");
361
+ if (!n) return;
362
+ const t = h(n.pageType);
363
+ if (t)
365
364
  switch (a) {
366
365
  case "CREATE_PAGE":
367
- return (r = n.onCreate) == null ? void 0 : r.call(n, t);
366
+ return (r = t.onCreate) == null ? void 0 : r.call(t, n);
368
367
  case "UPDATE_PAGE":
369
- return (o = n.onUpdate) == null ? void 0 : o.call(n, t);
368
+ return (o = t.onUpdate) == null ? void 0 : o.call(t, n);
370
369
  case "DELETE_PAGE":
371
- return (c = n.onDelete) == null ? void 0 : c.call(n, t);
370
+ return (c = t.onDelete) == null ? void 0 : c.call(t, n);
372
371
  }
373
372
  }
374
373
  // APIS
@@ -381,36 +380,36 @@ class M {
381
380
  Object.keys(U).includes(e) ? this.setCurrentLang(e) : this.setCurrentLang(this.getFallbackLang());
382
381
  }
383
382
  async resolveLink(a, e) {
384
- const t = h(a);
385
- if (!t)
383
+ const n = h(a);
384
+ if (!n)
386
385
  return "/not-found";
387
- const n = this.isDraftMode(), r = this.getCurrentLang();
388
- return t.resolveLink ? await t.resolveLink(e, n, r) : await this.backend.handleAction({
386
+ const t = this.isDraftMode(), r = this.getCurrentLang();
387
+ return n.resolveLink ? await n.resolveLink(e, t, r) : await this.backend.handleAction({
389
388
  action: "GET_LINK",
390
389
  data: {
391
390
  pageType: a,
392
391
  id: e,
393
- draft: n,
392
+ draft: t,
394
393
  lang: r
395
394
  }
396
395
  });
397
396
  }
398
397
  async getPageBySlug(a) {
399
- const e = this.isDraftMode(), t = {};
400
- return w().forEach((n) => {
401
- m(n, "dynamicSegments") && n.dynamicSegments && (t[n.key] = n.dynamicSegments);
398
+ const e = this.isDraftMode(), n = {};
399
+ return w().forEach((t) => {
400
+ m(t, "dynamicSegments") && t.dynamicSegments && (n[t.key] = t.dynamicSegments);
402
401
  }), await this.backend.handleAction({
403
402
  action: "GET_PAGE_META",
404
- data: { slug: a, draft: e, dynamicSegments: t }
403
+ data: { slug: a, draft: e, dynamicSegments: n }
405
404
  });
406
405
  }
407
406
  async getFullPage(a) {
408
- const e = this.isDraftMode(), t = this.getCurrentLang(), n = this.getFallbackLang();
407
+ const e = this.isDraftMode(), n = this.getCurrentLang(), t = this.getFallbackLang();
409
408
  return await this.backend.handleAction({
410
409
  action: "GET_PAGE",
411
410
  data: {
412
411
  id: a,
413
- lang: n === t ? void 0 : t,
412
+ lang: t === n ? void 0 : n,
414
413
  draft: e,
415
414
  mergePartials: !0
416
415
  }
@@ -425,11 +424,11 @@ class M {
425
424
  }
426
425
  async getPageData(a, e = {}) {
427
426
  var l;
428
- const t = this.isDraftMode(), n = this.getCurrentLang(), r = h(a), [o, c] = await Promise.all([
427
+ const n = this.isDraftMode(), t = this.getCurrentLang(), r = h(a), [o, c] = await Promise.all([
429
428
  this.getGlobalData(),
430
429
  ((l = r == null ? void 0 : r.dataProvider) == null ? void 0 : l.call(r, {
431
- lang: n,
432
- draft: t,
430
+ lang: t,
431
+ draft: n,
433
432
  inBuilder: !1,
434
433
  pageProps: e
435
434
  })) || Promise.resolve({})
@@ -456,27 +455,26 @@ class D {
456
455
  this.apiKey = a, this.apiUrl = e;
457
456
  }
458
457
  async handleUsersAction(a, e) {
459
- console.log(a, e, this.apiUrl);
460
- const t = await fetch(`${this.apiUrl}/v1/api/users`, {
458
+ const n = await fetch(`${this.apiUrl}/v1/api/users`, {
461
459
  method: "POST",
462
460
  body: JSON.stringify(a),
463
461
  headers: {
464
462
  "x-chai-api-key": this.apiKey,
465
463
  "x-chai-auth-token": e
466
464
  }
467
- }), n = await t.json();
468
- return m(n, "error") ? { ...n, status: t.status } : n;
465
+ }), t = await n.json();
466
+ return m(t, "error") ? { ...t, status: n.status } : t;
469
467
  }
470
468
  async handleAction(a, e) {
471
- const t = await fetch(`${this.apiUrl}/v1/api/chai`, {
469
+ const n = await fetch(`${this.apiUrl}/v1/api/chai`, {
472
470
  method: "POST",
473
471
  body: JSON.stringify(a),
474
472
  headers: {
475
473
  "x-chai-api-key": this.apiKey,
476
474
  "x-chai-auth-token": e
477
475
  }
478
- }), n = await t.json();
479
- return m(n, "error") ? { ...n, status: t.status } : n;
476
+ }), t = await n.json();
477
+ return m(t, "error") ? { ...t, status: n.status } : t;
480
478
  }
481
479
  async handleUpload(a, e) {
482
480
  return await (await fetch(`${this.apiUrl}/v1/api/chai`, {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "Suraj Air",
4
4
  "license": "Private",
5
5
  "homepage": "https://chaibuilder.com",
6
- "version": "0.4.0",
6
+ "version": "0.4.2",
7
7
  "type": "module",
8
8
  "files": [
9
9
  "dist"