@khanacademy/perseus-core 1.4.2 → 1.5.0

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.
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @typedef {Object} Errors utility for referencing the Perseus error taxonomy.
3
+ */
4
+ export declare const Errors: Readonly<{
5
+ /**
6
+ * @property {ErrorKind} Unknown The kind of error is not known.
7
+ */
8
+ Unknown: "Unknown";
9
+ /**
10
+ * @property {ErrorKind} Internal The error is internal to the executing code.
11
+ */
12
+ Internal: "Internal";
13
+ /**
14
+ * @property {ErrorKind} InvalidInput There was a problem with the provided
15
+ * input, such as the wrong format or a null value.
16
+ */
17
+ InvalidInput: "InvalidInput";
18
+ /**
19
+ * @property {ErrorKind} NotAllowed There was a problem due to the state of
20
+ * the system not matching the requested operation or input. For example,
21
+ * trying to create a username that is valid, but is already taken by
22
+ * another user. Use {@link InvalidInput} instead when the input isn't
23
+ * valid regardless of the state of the system. Use {@link NotFound} when
24
+ * the failure is due to not being able to find a resource.
25
+ */
26
+ NotAllowed: "NotAllowed";
27
+ /**
28
+ * @property {ErrorKind} TransientService There was a problem when making a
29
+ * request to a service.
30
+ */
31
+ TransientService: "TransientService";
32
+ /**
33
+ * @property {ErrorKind} Service There was a non-transient problem when
34
+ * making a request to service.
35
+ */
36
+ Service: "Service";
37
+ }>;
38
+ /**
39
+ * @type {ErrorKind} The kind of error being reported
40
+ */
41
+ export type ErrorKind = (typeof Errors)[keyof typeof Errors];
@@ -0,0 +1,11 @@
1
+ import type { ErrorKind } from "./errors";
2
+ import type { Metadata } from "@khanacademy/wonder-stuff-core";
3
+ type Options = {
4
+ metadata?: Metadata | null | undefined;
5
+ };
6
+ export declare class PerseusError extends Error {
7
+ kind: ErrorKind;
8
+ metadata: Metadata | null | undefined;
9
+ constructor(message: string, kind: ErrorKind, options?: Options);
10
+ }
11
+ export {};
package/dist/es/index.js CHANGED
@@ -42,8 +42,60 @@ const addLibraryVersionToPerseusDebug = (libraryName, libraryVersion) => {
42
42
 
43
43
  // This file is processed by a Rollup plugin (replace) to inject the production
44
44
  const libName = "@khanacademy/perseus-core";
45
- const libVersion = "1.4.2";
45
+ const libVersion = "1.5.0";
46
46
  addLibraryVersionToPerseusDebug(libName, libVersion);
47
47
 
48
- export { addLibraryVersionToPerseusDebug, libVersion };
48
+ /**
49
+ * @typedef {Object} Errors utility for referencing the Perseus error taxonomy.
50
+ */
51
+ const Errors = Object.freeze({
52
+ /**
53
+ * @property {ErrorKind} Unknown The kind of error is not known.
54
+ */
55
+ Unknown: "Unknown",
56
+ /**
57
+ * @property {ErrorKind} Internal The error is internal to the executing code.
58
+ */
59
+ Internal: "Internal",
60
+ /**
61
+ * @property {ErrorKind} InvalidInput There was a problem with the provided
62
+ * input, such as the wrong format or a null value.
63
+ */
64
+ InvalidInput: "InvalidInput",
65
+ /**
66
+ * @property {ErrorKind} NotAllowed There was a problem due to the state of
67
+ * the system not matching the requested operation or input. For example,
68
+ * trying to create a username that is valid, but is already taken by
69
+ * another user. Use {@link InvalidInput} instead when the input isn't
70
+ * valid regardless of the state of the system. Use {@link NotFound} when
71
+ * the failure is due to not being able to find a resource.
72
+ */
73
+ NotAllowed: "NotAllowed",
74
+ /**
75
+ * @property {ErrorKind} TransientService There was a problem when making a
76
+ * request to a service.
77
+ */
78
+ TransientService: "TransientService",
79
+ /**
80
+ * @property {ErrorKind} Service There was a non-transient problem when
81
+ * making a request to service.
82
+ */
83
+ Service: "Service"
84
+ });
85
+
86
+ /**
87
+ * @type {ErrorKind} The kind of error being reported
88
+ */
89
+
90
+ class PerseusError extends Error {
91
+ constructor(message, kind, options) {
92
+ super(message);
93
+ this.kind = void 0;
94
+ this.metadata = void 0;
95
+ this.kind = kind;
96
+ this.metadata = options == null ? void 0 : options.metadata;
97
+ }
98
+ }
99
+
100
+ export { Errors, PerseusError, addLibraryVersionToPerseusDebug, libVersion };
49
101
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/utils/add-library-version-to-perseus-debug.ts","../../src/version.ts"],"sourcesContent":["/**\n * Adds the given perseus library version information to the __perseus_debug__\n * object and ensures that the object is attached to `globalThis` (`window` in\n * browser environments).\n *\n * This allows each library to provide runtime version information to assist in\n * debugging in production environments.\n */\nexport const addLibraryVersionToPerseusDebug = (\n libraryName: string,\n libraryVersion: string,\n) => {\n // If the library version is the default value, then we don't want to\n // prefix it with a \"v\" to indicate that it is a version number.\n let prefix = \"v\";\n if (libraryVersion === \"__lib_version__\") {\n prefix = \"\";\n }\n const formattedVersion = `${prefix}${libraryVersion}`;\n\n if (typeof globalThis !== \"undefined\") {\n globalThis.__perseus_debug__ = globalThis.__perseus_debug__ ?? {};\n\n const existingVersionEntry = globalThis.__perseus_debug__[libraryName];\n if (existingVersionEntry) {\n // If we already have an entry and it doesn't match the registered\n // version, we morph the entry into an array and log a warning.\n if (existingVersionEntry !== formattedVersion) {\n // Existing entry might be an array already (oops, at least 2\n // versions of the library already loaded!).\n const allVersions = Array.isArray(existingVersionEntry)\n ? existingVersionEntry\n : [existingVersionEntry];\n allVersions.push(formattedVersion);\n\n globalThis.__perseus_debug__[libraryName] = allVersions;\n\n // eslint-disable-next-line no-console\n console.warn(\n `Multiple versions of ${libraryName} loaded on this page: ${allVersions\n .sort()\n .join(\", \")}`,\n );\n }\n } else {\n globalThis.__perseus_debug__[libraryName] = formattedVersion;\n }\n } else {\n // eslint-disable-next-line no-console\n console.warn(`globalThis not found found (${formattedVersion})`);\n }\n};\n","// This file is processed by a Rollup plugin (replace) to inject the production\n// version number during the release build.\n// In dev, you'll never see the version number.\n\nimport {addLibraryVersionToPerseusDebug} from \"./utils/add-library-version-to-perseus-debug\";\n\nconst libName = \"@khanacademy/perseus-core\";\nexport const libVersion = \"__lib_version__\";\n\naddLibraryVersionToPerseusDebug(libName, libVersion);\n"],"names":["addLibraryVersionToPerseusDebug","libraryName","libraryVersion","prefix","formattedVersion","globalThis","_globalThis$__perseus","__perseus_debug__","existingVersionEntry","allVersions","Array","isArray","push","console","warn","sort","join","libName","libVersion"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MACaA,+BAA+B,GAAGA,CAC3CC,WAAmB,EACnBC,cAAsB,KACrB;AACD;AACA;EACA,IAAIC,MAAM,GAAG,GAAG,CAAA;EAChB,IAAID,cAAc,KAAK,iBAAiB,EAAE;AACtCC,IAAAA,MAAM,GAAG,EAAE,CAAA;AACf,GAAA;AACA,EAAA,MAAMC,gBAAgB,GAAI,CAAA,EAAED,MAAO,CAAA,EAAED,cAAe,CAAC,CAAA,CAAA;AAErD,EAAA,IAAI,OAAOG,UAAU,KAAK,WAAW,EAAE;AAAA,IAAA,IAAAC,qBAAA,CAAA;AACnCD,IAAAA,UAAU,CAACE,iBAAiB,GAAAD,CAAAA,qBAAA,GAAGD,UAAU,CAACE,iBAAiB,KAAAD,IAAAA,GAAAA,qBAAA,GAAI,EAAE,CAAA;AAEjE,IAAA,MAAME,oBAAoB,GAAGH,UAAU,CAACE,iBAAiB,CAACN,WAAW,CAAC,CAAA;AACtE,IAAA,IAAIO,oBAAoB,EAAE;AACtB;AACA;MACA,IAAIA,oBAAoB,KAAKJ,gBAAgB,EAAE;AAC3C;AACA;AACA,QAAA,MAAMK,WAAW,GAAGC,KAAK,CAACC,OAAO,CAACH,oBAAoB,CAAC,GACjDA,oBAAoB,GACpB,CAACA,oBAAoB,CAAC,CAAA;AAC5BC,QAAAA,WAAW,CAACG,IAAI,CAACR,gBAAgB,CAAC,CAAA;AAElCC,QAAAA,UAAU,CAACE,iBAAiB,CAACN,WAAW,CAAC,GAAGQ,WAAW,CAAA;;AAEvD;AACAI,QAAAA,OAAO,CAACC,IAAI,CACP,CAAuBb,qBAAAA,EAAAA,WAAY,yBAAwBQ,WAAW,CAClEM,IAAI,EAAE,CACNC,IAAI,CAAC,IAAI,CAAE,EACpB,CAAC,CAAA;AACL,OAAA;AACJ,KAAC,MAAM;AACHX,MAAAA,UAAU,CAACE,iBAAiB,CAACN,WAAW,CAAC,GAAGG,gBAAgB,CAAA;AAChE,KAAA;AACJ,GAAC,MAAM;AACH;AACAS,IAAAA,OAAO,CAACC,IAAI,CAAE,CAA8BV,4BAAAA,EAAAA,gBAAiB,GAAE,CAAC,CAAA;AACpE,GAAA;AACJ;;ACnDA;AAMA,MAAMa,OAAO,GAAG,2BAA2B,CAAA;AACpC,MAAMC,UAAU,GAAG,QAAiB;AAE3ClB,+BAA+B,CAACiB,OAAO,EAAEC,UAAU,CAAC;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/utils/add-library-version-to-perseus-debug.ts","../../src/version.ts","../../src/error/errors.ts","../../src/error/perseus-error.ts"],"sourcesContent":["/**\n * Adds the given perseus library version information to the __perseus_debug__\n * object and ensures that the object is attached to `globalThis` (`window` in\n * browser environments).\n *\n * This allows each library to provide runtime version information to assist in\n * debugging in production environments.\n */\nexport const addLibraryVersionToPerseusDebug = (\n libraryName: string,\n libraryVersion: string,\n) => {\n // If the library version is the default value, then we don't want to\n // prefix it with a \"v\" to indicate that it is a version number.\n let prefix = \"v\";\n if (libraryVersion === \"__lib_version__\") {\n prefix = \"\";\n }\n const formattedVersion = `${prefix}${libraryVersion}`;\n\n if (typeof globalThis !== \"undefined\") {\n globalThis.__perseus_debug__ = globalThis.__perseus_debug__ ?? {};\n\n const existingVersionEntry = globalThis.__perseus_debug__[libraryName];\n if (existingVersionEntry) {\n // If we already have an entry and it doesn't match the registered\n // version, we morph the entry into an array and log a warning.\n if (existingVersionEntry !== formattedVersion) {\n // Existing entry might be an array already (oops, at least 2\n // versions of the library already loaded!).\n const allVersions = Array.isArray(existingVersionEntry)\n ? existingVersionEntry\n : [existingVersionEntry];\n allVersions.push(formattedVersion);\n\n globalThis.__perseus_debug__[libraryName] = allVersions;\n\n // eslint-disable-next-line no-console\n console.warn(\n `Multiple versions of ${libraryName} loaded on this page: ${allVersions\n .sort()\n .join(\", \")}`,\n );\n }\n } else {\n globalThis.__perseus_debug__[libraryName] = formattedVersion;\n }\n } else {\n // eslint-disable-next-line no-console\n console.warn(`globalThis not found found (${formattedVersion})`);\n }\n};\n","// This file is processed by a Rollup plugin (replace) to inject the production\n// version number during the release build.\n// In dev, you'll never see the version number.\n\nimport {addLibraryVersionToPerseusDebug} from \"./utils/add-library-version-to-perseus-debug\";\n\nconst libName = \"@khanacademy/perseus-core\";\nexport const libVersion = \"__lib_version__\";\n\naddLibraryVersionToPerseusDebug(libName, libVersion);\n","/**\n * @typedef {Object} Errors utility for referencing the Perseus error taxonomy.\n */\nexport const Errors = Object.freeze({\n /**\n * @property {ErrorKind} Unknown The kind of error is not known.\n */\n Unknown: \"Unknown\",\n /**\n * @property {ErrorKind} Internal The error is internal to the executing code.\n */\n Internal: \"Internal\",\n /**\n * @property {ErrorKind} InvalidInput There was a problem with the provided\n * input, such as the wrong format or a null value.\n */\n InvalidInput: \"InvalidInput\",\n /**\n * @property {ErrorKind} NotAllowed There was a problem due to the state of\n * the system not matching the requested operation or input. For example,\n * trying to create a username that is valid, but is already taken by\n * another user. Use {@link InvalidInput} instead when the input isn't\n * valid regardless of the state of the system. Use {@link NotFound} when\n * the failure is due to not being able to find a resource.\n */\n NotAllowed: \"NotAllowed\",\n /**\n * @property {ErrorKind} TransientService There was a problem when making a\n * request to a service.\n */\n TransientService: \"TransientService\",\n /**\n * @property {ErrorKind} Service There was a non-transient problem when\n * making a request to service.\n */\n Service: \"Service\",\n});\n\n/**\n * @type {ErrorKind} The kind of error being reported\n */\nexport type ErrorKind = (typeof Errors)[keyof typeof Errors];\n","import type {ErrorKind} from \"./errors\";\nimport type {Metadata} from \"@khanacademy/wonder-stuff-core\";\n\ntype Options = {\n metadata?: Metadata | null | undefined;\n};\n\nexport class PerseusError extends Error {\n kind: ErrorKind;\n metadata: Metadata | null | undefined;\n\n constructor(message: string, kind: ErrorKind, options?: Options) {\n super(message);\n this.kind = kind;\n this.metadata = options?.metadata;\n }\n}\n"],"names":["addLibraryVersionToPerseusDebug","libraryName","libraryVersion","prefix","formattedVersion","globalThis","_globalThis$__perseus","__perseus_debug__","existingVersionEntry","allVersions","Array","isArray","push","console","warn","sort","join","libName","libVersion","Errors","Object","freeze","Unknown","Internal","InvalidInput","NotAllowed","TransientService","Service","PerseusError","Error","constructor","message","kind","options","metadata"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MACaA,+BAA+B,GAAGA,CAC3CC,WAAmB,EACnBC,cAAsB,KACrB;AACD;AACA;EACA,IAAIC,MAAM,GAAG,GAAG,CAAA;EAChB,IAAID,cAAc,KAAK,iBAAiB,EAAE;AACtCC,IAAAA,MAAM,GAAG,EAAE,CAAA;AACf,GAAA;AACA,EAAA,MAAMC,gBAAgB,GAAI,CAAA,EAAED,MAAO,CAAA,EAAED,cAAe,CAAC,CAAA,CAAA;AAErD,EAAA,IAAI,OAAOG,UAAU,KAAK,WAAW,EAAE;AAAA,IAAA,IAAAC,qBAAA,CAAA;AACnCD,IAAAA,UAAU,CAACE,iBAAiB,GAAAD,CAAAA,qBAAA,GAAGD,UAAU,CAACE,iBAAiB,KAAAD,IAAAA,GAAAA,qBAAA,GAAI,EAAE,CAAA;AAEjE,IAAA,MAAME,oBAAoB,GAAGH,UAAU,CAACE,iBAAiB,CAACN,WAAW,CAAC,CAAA;AACtE,IAAA,IAAIO,oBAAoB,EAAE;AACtB;AACA;MACA,IAAIA,oBAAoB,KAAKJ,gBAAgB,EAAE;AAC3C;AACA;AACA,QAAA,MAAMK,WAAW,GAAGC,KAAK,CAACC,OAAO,CAACH,oBAAoB,CAAC,GACjDA,oBAAoB,GACpB,CAACA,oBAAoB,CAAC,CAAA;AAC5BC,QAAAA,WAAW,CAACG,IAAI,CAACR,gBAAgB,CAAC,CAAA;AAElCC,QAAAA,UAAU,CAACE,iBAAiB,CAACN,WAAW,CAAC,GAAGQ,WAAW,CAAA;;AAEvD;AACAI,QAAAA,OAAO,CAACC,IAAI,CACP,CAAuBb,qBAAAA,EAAAA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GD,OAAO,IAAPA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,OAAO,CAAEC,QAAQ,CAAA;AACrC,GAAA;AACJ;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  export type { PerseusAnalyticsEvent, AnalyticsEventHandlerFn } from "./analytics";
2
2
  export type { KEScore, KeypadContextRendererInterface, RendererInterface, } from "./types";
3
+ export type { ErrorKind } from "./error/errors";
3
4
  export { addLibraryVersionToPerseusDebug } from "./utils/add-library-version-to-perseus-debug";
4
5
  export { libVersion } from "./version";
6
+ export { Errors } from "./error/errors";
7
+ export { PerseusError } from "./error/perseus-error";
package/dist/index.js CHANGED
@@ -45,9 +45,63 @@ const addLibraryVersionToPerseusDebug = (libraryName, libraryVersion) => {
45
45
 
46
46
  // This file is processed by a Rollup plugin (replace) to inject the production
47
47
  const libName = "@khanacademy/perseus-core";
48
- const libVersion = "1.4.2";
48
+ const libVersion = "1.5.0";
49
49
  addLibraryVersionToPerseusDebug(libName, libVersion);
50
50
 
51
+ /**
52
+ * @typedef {Object} Errors utility for referencing the Perseus error taxonomy.
53
+ */
54
+ const Errors = Object.freeze({
55
+ /**
56
+ * @property {ErrorKind} Unknown The kind of error is not known.
57
+ */
58
+ Unknown: "Unknown",
59
+ /**
60
+ * @property {ErrorKind} Internal The error is internal to the executing code.
61
+ */
62
+ Internal: "Internal",
63
+ /**
64
+ * @property {ErrorKind} InvalidInput There was a problem with the provided
65
+ * input, such as the wrong format or a null value.
66
+ */
67
+ InvalidInput: "InvalidInput",
68
+ /**
69
+ * @property {ErrorKind} NotAllowed There was a problem due to the state of
70
+ * the system not matching the requested operation or input. For example,
71
+ * trying to create a username that is valid, but is already taken by
72
+ * another user. Use {@link InvalidInput} instead when the input isn't
73
+ * valid regardless of the state of the system. Use {@link NotFound} when
74
+ * the failure is due to not being able to find a resource.
75
+ */
76
+ NotAllowed: "NotAllowed",
77
+ /**
78
+ * @property {ErrorKind} TransientService There was a problem when making a
79
+ * request to a service.
80
+ */
81
+ TransientService: "TransientService",
82
+ /**
83
+ * @property {ErrorKind} Service There was a non-transient problem when
84
+ * making a request to service.
85
+ */
86
+ Service: "Service"
87
+ });
88
+
89
+ /**
90
+ * @type {ErrorKind} The kind of error being reported
91
+ */
92
+
93
+ class PerseusError extends Error {
94
+ kind;
95
+ metadata;
96
+ constructor(message, kind, options) {
97
+ super(message);
98
+ this.kind = kind;
99
+ this.metadata = options?.metadata;
100
+ }
101
+ }
102
+
103
+ exports.Errors = Errors;
104
+ exports.PerseusError = PerseusError;
51
105
  exports.addLibraryVersionToPerseusDebug = addLibraryVersionToPerseusDebug;
52
106
  exports.libVersion = libVersion;
53
107
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/utils/add-library-version-to-perseus-debug.ts","../src/version.ts"],"sourcesContent":["/**\n * Adds the given perseus library version information to the __perseus_debug__\n * object and ensures that the object is attached to `globalThis` (`window` in\n * browser environments).\n *\n * This allows each library to provide runtime version information to assist in\n * debugging in production environments.\n */\nexport const addLibraryVersionToPerseusDebug = (\n libraryName: string,\n libraryVersion: string,\n) => {\n // If the library version is the default value, then we don't want to\n // prefix it with a \"v\" to indicate that it is a version number.\n let prefix = \"v\";\n if (libraryVersion === \"__lib_version__\") {\n prefix = \"\";\n }\n const formattedVersion = `${prefix}${libraryVersion}`;\n\n if (typeof globalThis !== \"undefined\") {\n globalThis.__perseus_debug__ = globalThis.__perseus_debug__ ?? {};\n\n const existingVersionEntry = globalThis.__perseus_debug__[libraryName];\n if (existingVersionEntry) {\n // If we already have an entry and it doesn't match the registered\n // version, we morph the entry into an array and log a warning.\n if (existingVersionEntry !== formattedVersion) {\n // Existing entry might be an array already (oops, at least 2\n // versions of the library already loaded!).\n const allVersions = Array.isArray(existingVersionEntry)\n ? existingVersionEntry\n : [existingVersionEntry];\n allVersions.push(formattedVersion);\n\n globalThis.__perseus_debug__[libraryName] = allVersions;\n\n // eslint-disable-next-line no-console\n console.warn(\n `Multiple versions of ${libraryName} loaded on this page: ${allVersions\n .sort()\n .join(\", \")}`,\n );\n }\n } else {\n globalThis.__perseus_debug__[libraryName] = formattedVersion;\n }\n } else {\n // eslint-disable-next-line no-console\n console.warn(`globalThis not found found (${formattedVersion})`);\n }\n};\n","// This file is processed by a Rollup plugin (replace) to inject the production\n// version number during the release build.\n// In dev, you'll never see the version number.\n\nimport {addLibraryVersionToPerseusDebug} from \"./utils/add-library-version-to-perseus-debug\";\n\nconst libName = \"@khanacademy/perseus-core\";\nexport const libVersion = \"__lib_version__\";\n\naddLibraryVersionToPerseusDebug(libName, libVersion);\n"],"names":["addLibraryVersionToPerseusDebug","libraryName","libraryVersion","prefix","formattedVersion","globalThis","__perseus_debug__","existingVersionEntry","allVersions","Array","isArray","push","console","warn","sort","join","libName","libVersion"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MACaA,+BAA+B,GAAGA,CAC3CC,WAAmB,EACnBC,cAAsB,KACrB;AACD;AACA;EACA,IAAIC,MAAM,GAAG,GAAG,CAAA;EAChB,IAAID,cAAc,KAAK,iBAAiB,EAAE;AACtCC,IAAAA,MAAM,GAAG,EAAE,CAAA;AACf,GAAA;AACA,EAAA,MAAMC,gBAAgB,GAAI,CAAA,EAAED,MAAO,CAAA,EAAED,cAAe,CAAC,CAAA,CAAA;AAErD,EAAA,IAAI,OAAOG,UAAU,KAAK,WAAW,EAAE;IACnCA,UAAU,CAACC,iBAAiB,GAAGD,UAAU,CAACC,iBAAiB,IAAI,EAAE,CAAA;AAEjE,IAAA,MAAMC,oBAAoB,GAAGF,UAAU,CAACC,iBAAiB,CAACL,WAAW,CAAC,CAAA;AACtE,IAAA,IAAIM,oBAAoB,EAAE;AACtB;AACA;MACA,IAAIA,oBAAoB,KAAKH,gBAAgB,EAAE;AAC3C;AACA;AACA,QAAA,MAAMI,WAAW,GAAGC,KAAK,CAACC,OAAO,CAACH,oBAAoB,CAAC,GACjDA,oBAAoB,GACpB,CAACA,oBAAoB,CAAC,CAAA;AAC5BC,QAAAA,WAAW,CAACG,IAAI,CAACP,gBAAgB,CAAC,CAAA;AAElCC,QAAAA,UAAU,CAACC,iBAAiB,CAACL,WAAW,CAAC,GAAGO,WAAW,CAAA;;AAEvD;AACAI,QAAAA,OAAO,CAACC,IAAI,CACP,CAAuBZ,qBAAAA,EAAAA,WAAY,yBAAwBO,WAAW,CAClEM,IAAI,EAAE,CACNC,IAAI,CAAC,IAAI,CAAE,EACpB,CAAC,CAAA;AACL,OAAA;AACJ,KAAC,MAAM;AACHV,MAAAA,UAAU,CAACC,iBAAiB,CAACL,WAAW,CAAC,GAAGG,gBAAgB,CAAA;AAChE,KAAA;AACJ,GAAC,MAAM;AACH;AACAQ,IAAAA,OAAO,CAACC,IAAI,CAAE,CAA8BT,4BAAAA,EAAAA,gBAAiB,GAAE,CAAC,CAAA;AACpE,GAAA;AACJ;;ACnDA;AAMA,MAAMY,OAAO,GAAG,2BAA2B,CAAA;AACpC,MAAMC,UAAU,GAAG,QAAiB;AAE3CjB,+BAA+B,CAACgB,OAAO,EAAEC,UAAU,CAAC;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/utils/add-library-version-to-perseus-debug.ts","../src/version.ts","../src/error/errors.ts","../src/error/perseus-error.ts"],"sourcesContent":["/**\n * Adds the given perseus library version information to the __perseus_debug__\n * object and ensures that the object is attached to `globalThis` (`window` in\n * browser environments).\n *\n * This allows each library to provide runtime version information to assist in\n * debugging in production environments.\n */\nexport const addLibraryVersionToPerseusDebug = (\n libraryName: string,\n libraryVersion: string,\n) => {\n // If the library version is the default value, then we don't want to\n // prefix it with a \"v\" to indicate that it is a version number.\n let prefix = \"v\";\n if (libraryVersion === \"__lib_version__\") {\n prefix = \"\";\n }\n const formattedVersion = `${prefix}${libraryVersion}`;\n\n if (typeof globalThis !== \"undefined\") {\n globalThis.__perseus_debug__ = globalThis.__perseus_debug__ ?? {};\n\n const existingVersionEntry = globalThis.__perseus_debug__[libraryName];\n if (existingVersionEntry) {\n // If we already have an entry and it doesn't match the registered\n // version, we morph the entry into an array and log a warning.\n if (existingVersionEntry !== formattedVersion) {\n // Existing entry might be an array already (oops, at least 2\n // versions of the library already loaded!).\n const allVersions = Array.isArray(existingVersionEntry)\n ? existingVersionEntry\n : [existingVersionEntry];\n allVersions.push(formattedVersion);\n\n globalThis.__perseus_debug__[libraryName] = allVersions;\n\n // eslint-disable-next-line no-console\n console.warn(\n `Multiple versions of ${libraryName} loaded on this page: ${allVersions\n .sort()\n .join(\", \")}`,\n );\n }\n } else {\n globalThis.__perseus_debug__[libraryName] = formattedVersion;\n }\n } else {\n // eslint-disable-next-line no-console\n console.warn(`globalThis not found found (${formattedVersion})`);\n }\n};\n","// This file is processed by a Rollup plugin (replace) to inject the production\n// version number during the release build.\n// In dev, you'll never see the version number.\n\nimport {addLibraryVersionToPerseusDebug} from \"./utils/add-library-version-to-perseus-debug\";\n\nconst libName = \"@khanacademy/perseus-core\";\nexport const libVersion = \"__lib_version__\";\n\naddLibraryVersionToPerseusDebug(libName, libVersion);\n","/**\n * @typedef {Object} Errors utility for referencing the Perseus error taxonomy.\n */\nexport const Errors = Object.freeze({\n /**\n * @property {ErrorKind} Unknown The kind of error is not known.\n */\n Unknown: \"Unknown\",\n /**\n * @property {ErrorKind} Internal The error is internal to the executing code.\n */\n Internal: \"Internal\",\n /**\n * @property {ErrorKind} InvalidInput There was a problem with the provided\n * input, such as the wrong format or a null value.\n */\n InvalidInput: \"InvalidInput\",\n /**\n * @property {ErrorKind} NotAllowed There was a problem due to the state of\n * the system not matching the requested operation or input. For example,\n * trying to create a username that is valid, but is already taken by\n * another user. Use {@link InvalidInput} instead when the input isn't\n * valid regardless of the state of the system. Use {@link NotFound} when\n * the failure is due to not being able to find a resource.\n */\n NotAllowed: \"NotAllowed\",\n /**\n * @property {ErrorKind} TransientService There was a problem when making a\n * request to a service.\n */\n TransientService: \"TransientService\",\n /**\n * @property {ErrorKind} Service There was a non-transient problem when\n * making a request to service.\n */\n Service: \"Service\",\n});\n\n/**\n * @type {ErrorKind} The kind of error being reported\n */\nexport type ErrorKind = (typeof Errors)[keyof typeof Errors];\n","import type {ErrorKind} from \"./errors\";\nimport type {Metadata} from \"@khanacademy/wonder-stuff-core\";\n\ntype Options = {\n metadata?: Metadata | null | undefined;\n};\n\nexport class PerseusError extends Error {\n kind: ErrorKind;\n metadata: Metadata | null | undefined;\n\n constructor(message: string, kind: ErrorKind, options?: Options) {\n super(message);\n this.kind = kind;\n this.metadata = options?.metadata;\n }\n}\n"],"names":["addLibraryVersionToPerseusDebug","libraryName","libraryVersion","prefix","formattedVersion","globalThis","__perseus_debug__","existingVersionEntry","allVersions","Array","isArray","push","console","warn","sort","join","libName","libVersion","Errors","Object","freeze","Unknown","Internal","InvalidInput","NotAllowed","TransientService","Service","PerseusError","Error","kind","metadata","constructor","message","options"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MACaA,+BAA+B,GAAGA,CAC3CC,WAAmB,EACnBC,cAAsB,KACrB;AACD;AACA;EACA,IAAIC,MAAM,GAAG,GAAG,CAAA;EAChB,IAAID,cAAc,KAAK,iBAAiB,EAAE;AACtCC,IAAAA,MAAM,GAAG,EAAE,CAAA;AACf,GAAA;AACA,EAAA,MAAMC,gBAAgB,GAAI,CAAA,EAAED,MAAO,CAAA,EAAED,cAAe,CAAC,CAAA,CAAA;AAErD,EAAA,IAAI,OAAOG,UAAU,KAAK,WAAW,EAAE;IACnCA,UAAU,CAACC,iBAAiB,GAAGD,UAAU,CAACC,iBAAiB,IAAI,EAAE,CAAA;AAEjE,IAAA,MAAMC,oBAAoB,GAAGF,UAAU,CAACC,iBAAiB,CAACL,WAAW,CAAC,CAAA;AACtE,IAAA,IAAIM,oBAAoB,EAAE;AACtB;AACA;MACA,IAAIA,oBAAoB,KAAKH,gBAAgB,EAAE;AAC3C;AACA;AACA,QAAA,MAAMI,WAAW,GAAGC,KAAK,CAAC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EACJC,QAAQ,CAAA;AAERC,EAAAA,WAAWA,CAACC,OAAe,EAAEH,IAAe,EAAEI,OAAiB,EAAE;IAC7D,KAAK,CAACD,OAAO,CAAC,CAAA;IACd,IAAI,CAACH,IAAI,GAAGA,IAAI,CAAA;AAChB,IAAA,IAAI,CAACC,QAAQ,GAAGG,OAAO,EAAEH,QAAQ,CAAA;AACrC,GAAA;AACJ;;;;;;;"}
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Shared Perseus infrastructure",
4
4
  "author": "Khan Academy",
5
5
  "license": "MIT",
6
- "version": "1.4.2",
6
+ "version": "1.5.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },