@lustre/sdk 3.0.3-dev.23 → 3.0.3-dev.24
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/api/MutationError.js +46 -0
- package/dist/api/MutationError.js.map +1 -0
- package/dist/api/WrappedMutation.js +3 -0
- package/dist/api/WrappedMutation.js.map +1 -0
- package/dist/api/sendMutation.js +18 -3
- package/dist/api/sendMutation.js.map +1 -1
- package/package.json +1 -1
- package/types/api/MutationError.d.ts +25 -0
- package/types/api/MutationError.d.ts.map +1 -0
- package/types/api/WrappedMutation.d.ts +9 -0
- package/types/api/WrappedMutation.d.ts.map +1 -0
- package/types/api/sendMutation.d.ts +1 -1
- package/types/api/sendMutation.d.ts.map +1 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MutationResponseError = exports.MutationValidationError = exports.MutationReferenceError = exports.MutationFetchError = exports.MutationError = void 0;
|
|
4
|
+
class MutationError extends Error {
|
|
5
|
+
constructor(mutation, message = "") {
|
|
6
|
+
super(message);
|
|
7
|
+
this.mutation = mutation;
|
|
8
|
+
Object.setPrototypeOf(this, MutationError.prototype);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.MutationError = MutationError;
|
|
12
|
+
class MutationFetchError extends MutationError {
|
|
13
|
+
constructor(query, message = "") {
|
|
14
|
+
super(query, message);
|
|
15
|
+
this.name = "MutationFetchError";
|
|
16
|
+
Object.setPrototypeOf(this, MutationFetchError.prototype);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.MutationFetchError = MutationFetchError;
|
|
20
|
+
class MutationReferenceError extends MutationError {
|
|
21
|
+
constructor(query, message = "") {
|
|
22
|
+
super(query, message);
|
|
23
|
+
this.name = "MutationReferenceError";
|
|
24
|
+
Object.setPrototypeOf(this, MutationReferenceError.prototype);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.MutationReferenceError = MutationReferenceError;
|
|
28
|
+
class MutationValidationError extends MutationError {
|
|
29
|
+
constructor(query, message = "") {
|
|
30
|
+
super(query, message);
|
|
31
|
+
this.name = "MutationValidationError";
|
|
32
|
+
Object.setPrototypeOf(this, MutationReferenceError.prototype);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.MutationValidationError = MutationValidationError;
|
|
36
|
+
class MutationResponseError extends MutationError {
|
|
37
|
+
constructor(query, status, errors, message = "") {
|
|
38
|
+
super(query, message);
|
|
39
|
+
this.name = "MutationResponseError";
|
|
40
|
+
this.errors = errors;
|
|
41
|
+
this.status = status;
|
|
42
|
+
Object.setPrototypeOf(this, MutationResponseError.prototype);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.MutationResponseError = MutationResponseError;
|
|
46
|
+
//# sourceMappingURL=MutationError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MutationError.js","sourceRoot":"","sources":["../../src/api/MutationError.ts"],"names":[],"mappings":";;;AAMA,MAAa,aAAc,SAAQ,KAAK;IAEtC,YAAY,QAAyB,EAAE,OAAO,GAAG,EAAE;QACjD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QAGxB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,aAAa,CAAC,SAAS,CAAC,CAAA;IACtD,CAAC;CACF;AATD,sCASC;AAKD,MAAa,kBAAmB,SAAQ,aAAa;IAEnD,YAAY,KAAsB,EAAE,OAAO,GAAG,EAAE;QAC9C,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QAFd,SAAI,GAAG,oBAAoB,CAAA;QAIlC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAA;IAC3D,CAAC;CACF;AAPD,gDAOC;AAKD,MAAa,sBAAuB,SAAQ,aAAa;IAEvD,YAAY,KAAsB,EAAE,OAAO,GAAG,EAAE;QAC9C,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QAFd,SAAI,GAAG,wBAAwB,CAAA;QAGtC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAA;IAC/D,CAAC;CACF;AAND,wDAMC;AAKD,MAAa,uBAAwB,SAAQ,aAAa;IAExD,YAAY,KAAsB,EAAE,OAAO,GAAG,EAAE;QAC9C,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QAFd,SAAI,GAAG,yBAAyB,CAAA;QAGvC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAA;IAC/D,CAAC;CACF;AAND,0DAMC;AAKD,MAAa,qBAAsB,SAAQ,aAAa;IAItD,YAAY,KAAsB,EAAE,MAAc,EAAE,MAAqB,EAAE,OAAO,GAAG,EAAE;QACrF,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QAJd,SAAI,GAAG,uBAAuB,CAAA;QAKrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,qBAAqB,CAAC,SAAS,CAAC,CAAA;IAC9D,CAAC;CACF;AAVD,sDAUC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WrappedMutation.js","sourceRoot":"","sources":["../../src/api/WrappedMutation.ts"],"names":[],"mappings":""}
|
package/dist/api/sendMutation.js
CHANGED
|
@@ -11,9 +11,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.sendMutation = void 0;
|
|
13
13
|
const QueryResolver_1 = require("./QueryResolver");
|
|
14
|
+
const MutationError_1 = require("./MutationError");
|
|
14
15
|
const sendMutation = (name, body, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
16
|
var _a;
|
|
16
17
|
const { queryResolver = (0, QueryResolver_1._getDefaultQueryResolver)() } = options;
|
|
18
|
+
const wrappedMutation = { name, body };
|
|
17
19
|
const headers = new Headers(Object.assign({ "Content-type": "application/json", Accept: "application/json", "Accept-Encoding": "gzip, compress" }, queryResolver.headers));
|
|
18
20
|
const apiKey = queryResolver.apiKey;
|
|
19
21
|
if (apiKey) {
|
|
@@ -25,9 +27,22 @@ const sendMutation = (name, body, options = {}) => __awaiter(void 0, void 0, voi
|
|
|
25
27
|
method: "POST",
|
|
26
28
|
headers,
|
|
27
29
|
});
|
|
28
|
-
const response = yield fetch(request)
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
const response = yield fetch(request).catch((error) => {
|
|
31
|
+
throw new MutationError_1.MutationFetchError(wrappedMutation, error.message);
|
|
32
|
+
});
|
|
33
|
+
const responseJson = (yield response.json().catch((error) => {
|
|
34
|
+
throw new MutationError_1.MutationValidationError(wrappedMutation, error.message);
|
|
35
|
+
}));
|
|
36
|
+
if (responseJson.effect === undefined) {
|
|
37
|
+
new MutationError_1.MutationReferenceError(wrappedMutation, "Mutation response effect not defined");
|
|
38
|
+
}
|
|
39
|
+
if (responseJson.errors === undefined) {
|
|
40
|
+
new MutationError_1.MutationReferenceError(wrappedMutation, "Mutation response errors not defined");
|
|
41
|
+
}
|
|
42
|
+
if (responseJson.effect === null) {
|
|
43
|
+
throw new MutationError_1.MutationResponseError(wrappedMutation, response.status, responseJson.errors);
|
|
44
|
+
}
|
|
45
|
+
return responseJson.effect;
|
|
31
46
|
});
|
|
32
47
|
exports.sendMutation = sendMutation;
|
|
33
48
|
//# sourceMappingURL=sendMutation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendMutation.js","sourceRoot":"","sources":["../../src/api/sendMutation.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAA6E;
|
|
1
|
+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AM,IAAI,uCAAuB,CAAC,eAAe,EAAE,KAAK,CAAC,OAAO,CAAC,CAAA;IACnE,CAAC,CAAC,CAAwB,CAAA;IAC1B,IAAI,YAAY,CAAC,MAAM,KAAK,SAAS,EAAE;QACrC,IAAI,sCAAsB,CAAC,eAAe,EAAE,sCAAsC,CAAC,CAAA;KACpF;IACD,IAAI,YAAY,CAAC,MAAM,KAAK,SAAS,EAAE;QACrC,IAAI,sCAAsB,CAAC,eAAe,EAAE,sCAAsC,CAAC,CAAA;KACpF;IACD,IAAI,YAAY,CAAC,MAAM,KAAK,IAAI,EAAE;QAChC,MAAM,IAAI,qCAAqB,CAAC,eAAe,EAAE,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,CAAA;KACvF;IACD,OAAO,YAAY,CAAC,MAAwB,CAAA;AAC9C,CAAC,CAAA,CAAA;AA9CY,QAAA,YAAY,gBA8CxB"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { WrappedMutation } from "./WrappedMutation";
|
|
2
|
+
import { ServerError } from "../schema";
|
|
3
|
+
export declare class MutationError extends Error {
|
|
4
|
+
readonly mutation: WrappedMutation;
|
|
5
|
+
constructor(mutation: WrappedMutation, message?: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class MutationFetchError extends MutationError {
|
|
8
|
+
readonly name = "MutationFetchError";
|
|
9
|
+
constructor(query: WrappedMutation, message?: string);
|
|
10
|
+
}
|
|
11
|
+
export declare class MutationReferenceError extends MutationError {
|
|
12
|
+
readonly name = "MutationReferenceError";
|
|
13
|
+
constructor(query: WrappedMutation, message?: string);
|
|
14
|
+
}
|
|
15
|
+
export declare class MutationValidationError extends MutationError {
|
|
16
|
+
readonly name = "MutationValidationError";
|
|
17
|
+
constructor(query: WrappedMutation, message?: string);
|
|
18
|
+
}
|
|
19
|
+
export declare class MutationResponseError extends MutationError {
|
|
20
|
+
readonly name = "MutationResponseError";
|
|
21
|
+
readonly status: number;
|
|
22
|
+
readonly errors: ServerError[];
|
|
23
|
+
constructor(query: WrappedMutation, status: number, errors: ServerError[], message?: string);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=MutationError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MutationError.d.ts","sourceRoot":"","sources":["../../src/api/MutationError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,0BAA6B;AACvD,OAAO,EAAE,WAAW,EAAE,kBAAgB;AAKtC,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAA;gBACtB,QAAQ,EAAE,eAAe,EAAE,OAAO,SAAK;CAOpD;AAKD,qBAAa,kBAAmB,SAAQ,aAAa;IACnD,QAAQ,CAAC,IAAI,wBAAuB;gBACxB,KAAK,EAAE,eAAe,EAAE,OAAO,SAAK;CAKjD;AAKD,qBAAa,sBAAuB,SAAQ,aAAa;IACvD,QAAQ,CAAC,IAAI,4BAA2B;gBAC5B,KAAK,EAAE,eAAe,EAAE,OAAO,SAAK;CAIjD;AAKD,qBAAa,uBAAwB,SAAQ,aAAa;IACxD,QAAQ,CAAC,IAAI,6BAA4B;gBAC7B,KAAK,EAAE,eAAe,EAAE,OAAO,SAAK;CAIjD;AAKD,qBAAa,qBAAsB,SAAQ,aAAa;IACtD,QAAQ,CAAC,IAAI,2BAA0B;IACvC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,WAAW,EAAE,CAAA;gBAClB,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,OAAO,SAAK;CAMxF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ApiMutations } from "../schema";
|
|
2
|
+
type WrapMutation<T extends keyof ApiMutations> = {
|
|
3
|
+
name: T;
|
|
4
|
+
body: ApiMutations[T];
|
|
5
|
+
};
|
|
6
|
+
type DistributeWrapMutation<T extends keyof ApiMutations> = T extends keyof ApiMutations ? WrapMutation<T> : never;
|
|
7
|
+
export type WrappedMutation = DistributeWrapMutation<keyof ApiMutations>;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=WrappedMutation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WrappedMutation.d.ts","sourceRoot":"","sources":["../../src/api/WrappedMutation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,kBAAgB;AAIvC,KAAK,YAAY,CAAC,CAAC,SAAS,MAAM,YAAY,IAAI;IAChD,IAAI,EAAE,CAAC,CAAA;IACP,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,CAAA;CACtB,CAAA;AACD,KAAK,sBAAsB,CAAC,CAAC,SAAS,MAAM,YAAY,IAAI,CAAC,SAAS,MAAM,YAAY,GACpF,YAAY,CAAC,CAAC,CAAC,GACf,KAAK,CAAA;AAET,MAAM,MAAM,eAAe,GAAG,sBAAsB,CAAC,MAAM,YAAY,CAAC,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import QueryResolver from "./QueryResolver";
|
|
2
|
-
import {
|
|
2
|
+
import { ApiMutations, ApiEffects } from "../schema";
|
|
3
3
|
export declare const sendMutation: <MutationName extends "updateUserPersonalization", MutationBody extends ApiMutations[MutationName], MutationResult extends ApiEffects[MutationName]>(name: MutationName, body: MutationBody, options?: {
|
|
4
4
|
queryResolver?: QueryResolver;
|
|
5
5
|
}) => Promise<MutationResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendMutation.d.ts","sourceRoot":"","sources":["../../src/api/sendMutation.ts"],"names":[],"mappings":"AAAA,OAAO,aAA2C,wBAA2B;AAC7E,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"sendMutation.d.ts","sourceRoot":"","sources":["../../src/api/sendMutation.ts"],"names":[],"mappings":"AAAA,OAAO,aAA2C,wBAA2B;AAC7E,OAAO,EAAE,YAAY,EAAE,UAAU,EAAuB,kBAAgB;AAwBxE,eAAO,MAAM,YAAY,yMAOd;IACP,aAAa,CAAC,EAAE,aAAa,CAAA;CAC9B,4BAqCF,CAAA"}
|