flash-notifications 0.0.26 → 0.0.27

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.
@@ -1 +1 @@
1
- {"version":3,"file":"flash-notifications.d.ts","sourceRoot":"","sources":["../src/flash-notifications.js"],"names":[],"mappings":"AASA;IACE;;;OAGG;IACH,sBAHW,MAAM,GACJ,IAAI,CAIhB;IAED;;;OAGG;IACH,sBAHW,MAAM,GACJ,IAAI,CAIhB;IAED;;;OAGG;IACH,4BAHW,KAAK,GACH,IAAI,CAmChB;IAED;;;OAGG;IACH,wBAHW,MAAM,GACJ,IAAI,CAIhB;IAED;;;;;OAKG;IACH,kBAJG;QAAqB,IAAI,EAAjB,MAAM;QACO,IAAI,EAAjB,MAAM;KACd,GAAU,IAAI,CAoBhB;CACF"}
1
+ {"version":3,"file":"flash-notifications.d.ts","sourceRoot":"","sources":["../src/flash-notifications.js"],"names":[],"mappings":"AAOA;IACE;;;OAGG;IACH,sBAHW,MAAM,GACJ,IAAI,CAIhB;IAED;;;OAGG;IACH,sBAHW,MAAM,GACJ,IAAI,CAIhB;IAED;;;OAGG;IACH,4BAHW,KAAK,GACH,IAAI,CAqChB;IAED;;;OAGG;IACH,wBAHW,MAAM,GACJ,IAAI,CAIhB;IAED;;;;;OAKG;IACH,kBAJG;QAAqB,IAAI,EAAjB,MAAM;QACO,IAAI,EAAjB,MAAM;KACd,GAAU,IAAI,CAoBhB;CACF"}
@@ -1,6 +1,4 @@
1
1
  // @ts-check
2
- import BaseError from "@kaspernj/api-maker/build/base-error.js";
3
- import ValidationError from "@kaspernj/api-maker/build/validation-error.js";
4
2
  import { digg } from "diggerize";
5
3
  import configuration from "./configuration.js";
6
4
  import events from "./events.js";
@@ -24,7 +22,8 @@ export default class FlashNotifications {
24
22
  * @returns {void}
25
23
  */
26
24
  static errorResponse(error) {
27
- if (error instanceof ValidationError) {
25
+ // @ts-expect-error
26
+ if (error.apiMakerType == "ValidationError") {
28
27
  // @ts-expect-error
29
28
  if (error.hasUnhandledErrors()) {
30
29
  // @ts-expect-error
@@ -35,8 +34,9 @@ export default class FlashNotifications {
35
34
  const defaultValue = "Couldn't submit because of validation errors.";
36
35
  FlashNotifications.alert(configuration.translate("js.notification.couldnt_submit_because_of_validation_errors", { defaultValue }));
37
36
  }
37
+ // @ts-expect-error
38
38
  }
39
- else if (error instanceof BaseError) {
39
+ else if (error.apiMakerType == "BaseError") {
40
40
  // @ts-expect-error
41
41
  if (error.args.response && error.args.response.errors) {
42
42
  const errors = /** @type {Array<string | {message: string}[]>} */ (digg(error, "args", "response", "errors"));
@@ -1 +1 @@
1
- {"version":3,"file":"flash-notifications.js","sourceRoot":"","sources":["../src/flash-notifications.js"],"names":[],"mappings":"AAAA,YAAY;AAEZ,OAAO,SAAS,MAAM,yCAAyC,CAAA;AAC/D,OAAO,eAAe,MAAM,+CAA+C,CAAA;AAC3E,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAE9B,OAAO,aAAa,MAAM,oBAAoB,CAAA;AAC9C,OAAO,MAAM,MAAM,aAAa,CAAA;AAEhC,MAAM,CAAC,OAAO,OAAO,kBAAkB;IACrC;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,OAAO;QAClB,kBAAkB,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAC,CAAC,CAAA;IACzD,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,OAAO;QAClB,kBAAkB,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAC,CAAC,CAAA;IACzD,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,aAAa,CAAC,KAAK;QACxB,IAAI,KAAK,YAAY,eAAe,EAAE,CAAC;YACrC,mBAAmB;YACnB,IAAI,KAAK,CAAC,kBAAkB,EAAE,EAAE,CAAC;gBAC/B,mBAAmB;gBACnB,MAAM,sBAA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MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO;QACpB,kBAAkB,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAC,CAAC,CAAA;IAC3D,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,IAAI,CAAC,IAAI;QACd,IAAI,KAAK,CAAA;QAET,IAAI,IAAI,CAAC,IAAI,IAAI,OAAO,EAAE,CAAC;YACzB,KAAK,GAAG,aAAa,CAAC,SAAS,CAAC,iBAAiB,EAAE,EAAC,YAAY,EAAE,OAAO,EAAC,CAAC,CAAA;QAC7E,CAAC;aAAM,IAAI,IAAI,CAAC,IAAI,IAAI,OAAO,EAAE,CAAC;YAChC,KAAK,GAAG,aAAa,CAAC,SAAS,CAAC,iBAAiB,EAAE,EAAC,YAAY,EAAE,OAAO,EAAC,CAAC,CAAA;QAC7E,CAAC;aAAM,IAAI,IAAI,CAAC,IAAI,IAAI,SAAS,EAAE,CAAC;YAClC,KAAK,GAAG,aAAa,CAAC,SAAS,CAAC,mBAAmB,EAAE,EAAC,YAAY,EAAE,SAAS,EAAC,CAAC,CAAA;QACjF,CAAC;aAAM,CAAC;YACN,KAAK,GAAG,aAAa,CAAC,SAAS,CAAC,wBAAwB,EAAE,EAAC,YAAY,EAAE,cAAc,EAAC,CAAC,CAAA;QAC3F,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,kBAAkB,EAAE;YAC9B,OAAO,EAAE,IAAI,CAAC,IAAI;YAClB,KAAK;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["// @ts-check\n\nimport BaseError from \"@kaspernj/api-maker/build/base-error.js\"\nimport ValidationError from \"@kaspernj/api-maker/build/validation-error.js\"\nimport {digg} from \"diggerize\"\n\nimport configuration from \"./configuration.js\"\nimport events from \"./events.js\"\n\nexport default class FlashNotifications {\n /**\n * @param {string} message\n * @returns {void}\n */\n static alert(message) {\n FlashNotifications.show({type: \"alert\", text: message})\n }\n\n /**\n * @param {string} message\n * @returns {void}\n */\n static error(message) {\n FlashNotifications.show({type: \"error\", text: message})\n }\n\n /**\n * @param {Error} error\n * @returns {void}\n */\n static errorResponse(error) {\n if (error instanceof ValidationError) {\n // @ts-expect-error\n if (error.hasUnhandledErrors()) {\n // @ts-expect-error\n const unhandledErrorMessages = error.getUnhandledErrors().map((subError) => subError.getFullErrorMessages()).flat()\n\n FlashNotifications.error(unhandledErrorMessages.join(\". \"))\n } else {\n const defaultValue = \"Couldn't submit because of validation errors.\"\n\n FlashNotifications.alert(configuration.translate(\"js.notification.couldnt_submit_because_of_validation_errors\", {defaultValue}))\n }\n } else if (error instanceof BaseError) {\n // @ts-expect-error\n if (error.args.response && error.args.response.errors) {\n const errors = /** @type {Array<string | {message: string}[]>} */ (digg(error, \"args\", \"response\", \"errors\"))\n const errorMessages = errors.map((error) => {\n if (typeof error == \"string\") {\n return error\n }\n\n return digg(error, \"message\")\n })\n\n FlashNotifications.error(errorMessages.join(\". \"))\n } else {\n throw error\n }\n } else {\n console.error(`Didnt know what to do with that ${error.constructor.name}: ${error.message}`)\n throw error\n }\n }\n\n /**\n * @param {string} message\n * @returns {void}\n */\n static success(message) {\n FlashNotifications.show({type: \"success\", text: message})\n }\n\n /**\n * @param {object} args\n * @param {string} args.text\n * @param {string} args.type\n * @returns {void}\n */\n static show(args) {\n let title\n\n if (args.type == \"alert\") {\n title = configuration.translate(\"js.shared.alert\", {defaultValue: \"Alert\"})\n } else if (args.type == \"error\") {\n title = configuration.translate(\"js.shared.error\", {defaultValue: \"Error\"})\n } else if (args.type == \"success\") {\n title = configuration.translate(\"js.shared.success\", {defaultValue: \"Success\"})\n } else {\n title = configuration.translate(\"js.shared.notification\", {defaultValue: \"Notification\"})\n }\n\n events.emit(\"pushNotification\", {\n message: args.text,\n title,\n type: args.type\n })\n }\n}\n"]}
1
+ {"version":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QAC7E,CAAC;aAAM,IAAI,IAAI,CAAC,IAAI,IAAI,OAAO,EAAE,CAAC;YAChC,KAAK,GAAG,aAAa,CAAC,SAAS,CAAC,iBAAiB,EAAE,EAAC,YAAY,EAAE,OAAO,EAAC,CAAC,CAAA;QAC7E,CAAC;aAAM,IAAI,IAAI,CAAC,IAAI,IAAI,SAAS,EAAE,CAAC;YAClC,KAAK,GAAG,aAAa,CAAC,SAAS,CAAC,mBAAmB,EAAE,EAAC,YAAY,EAAE,SAAS,EAAC,CAAC,CAAA;QACjF,CAAC;aAAM,CAAC;YACN,KAAK,GAAG,aAAa,CAAC,SAAS,CAAC,wBAAwB,EAAE,EAAC,YAAY,EAAE,cAAc,EAAC,CAAC,CAAA;QAC3F,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,kBAAkB,EAAE;YAC9B,OAAO,EAAE,IAAI,CAAC,IAAI;YAClB,KAAK;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["// @ts-check\n\nimport {digg} from \"diggerize\"\n\nimport configuration from \"./configuration.js\"\nimport events from \"./events.js\"\n\nexport default class FlashNotifications {\n /**\n * @param {string} message\n * @returns {void}\n */\n static alert(message) {\n FlashNotifications.show({type: \"alert\", text: message})\n }\n\n /**\n * @param {string} message\n * @returns {void}\n */\n static error(message) {\n FlashNotifications.show({type: \"error\", text: message})\n }\n\n /**\n * @param {Error} error\n * @returns {void}\n */\n static errorResponse(error) {\n // @ts-expect-error\n if (error.apiMakerType == \"ValidationError\") {\n // @ts-expect-error\n if (error.hasUnhandledErrors()) {\n // @ts-expect-error\n const unhandledErrorMessages = error.getUnhandledErrors().map((subError) => subError.getFullErrorMessages()).flat()\n\n FlashNotifications.error(unhandledErrorMessages.join(\". \"))\n } else {\n const defaultValue = \"Couldn't submit because of validation errors.\"\n\n FlashNotifications.alert(configuration.translate(\"js.notification.couldnt_submit_because_of_validation_errors\", {defaultValue}))\n }\n // @ts-expect-error\n } else if (error.apiMakerType == \"BaseError\") {\n // @ts-expect-error\n if (error.args.response && error.args.response.errors) {\n const errors = /** @type {Array<string | {message: string}[]>} */ (digg(error, \"args\", \"response\", \"errors\"))\n const errorMessages = errors.map((error) => {\n if (typeof error == \"string\") {\n return error\n }\n\n return digg(error, \"message\")\n })\n\n FlashNotifications.error(errorMessages.join(\". \"))\n } else {\n throw error\n }\n } else {\n console.error(`Didnt know what to do with that ${error.constructor.name}: ${error.message}`)\n throw error\n }\n }\n\n /**\n * @param {string} message\n * @returns {void}\n */\n static success(message) {\n FlashNotifications.show({type: \"success\", text: message})\n }\n\n /**\n * @param {object} args\n * @param {string} args.text\n * @param {string} args.type\n * @returns {void}\n */\n static show(args) {\n let title\n\n if (args.type == \"alert\") {\n title = configuration.translate(\"js.shared.alert\", {defaultValue: \"Alert\"})\n } else if (args.type == \"error\") {\n title = configuration.translate(\"js.shared.error\", {defaultValue: \"Error\"})\n } else if (args.type == \"success\") {\n title = configuration.translate(\"js.shared.success\", {defaultValue: \"Success\"})\n } else {\n title = configuration.translate(\"js.shared.notification\", {defaultValue: \"Notification\"})\n }\n\n events.emit(\"pushNotification\", {\n message: args.text,\n title,\n type: args.type\n })\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flash-notifications",
3
- "version": "0.0.26",
3
+ "version": "0.0.27",
4
4
  "description": "My new module",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -1,7 +1,5 @@
1
1
  // @ts-check
2
2
 
3
- import BaseError from "@kaspernj/api-maker/build/base-error.js"
4
- import ValidationError from "@kaspernj/api-maker/build/validation-error.js"
5
3
  import {digg} from "diggerize"
6
4
 
7
5
  import configuration from "./configuration.js"
@@ -29,7 +27,8 @@ export default class FlashNotifications {
29
27
  * @returns {void}
30
28
  */
31
29
  static errorResponse(error) {
32
- if (error instanceof ValidationError) {
30
+ // @ts-expect-error
31
+ if (error.apiMakerType == "ValidationError") {
33
32
  // @ts-expect-error
34
33
  if (error.hasUnhandledErrors()) {
35
34
  // @ts-expect-error
@@ -41,7 +40,8 @@ export default class FlashNotifications {
41
40
 
42
41
  FlashNotifications.alert(configuration.translate("js.notification.couldnt_submit_because_of_validation_errors", {defaultValue}))
43
42
  }
44
- } else if (error instanceof BaseError) {
43
+ // @ts-expect-error
44
+ } else if (error.apiMakerType == "BaseError") {
45
45
  // @ts-expect-error
46
46
  if (error.args.response && error.args.response.errors) {
47
47
  const errors = /** @type {Array<string | {message: string}[]>} */ (digg(error, "args", "response", "errors"))