@lowerdeck/error 1.0.8 → 1.0.10

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":"defaultErrors.d.ts","sourceRoot":"","sources":["../src/defaultErrors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEjD,eAAO,IAAI,eAAe,GACxB,GAAG;IAAE,MAAM,EAAE,eAAe,EAAE,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,SAAS,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC,uDAQxF,CAAC;AAEL,eAAO,IAAI,mBAAmB,6DAI5B,CAAC;AAEH,eAAO,IAAI,eAAe,mDAIxB,CAAC;AAEH,wBAAgB,aAAa,CAAC,EAAE,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,SAAS,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AAC1I,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AAiB9F,eAAO,IAAI,iBAAiB,oDAK1B,CAAC;AAEH,eAAO,IAAI,cAAc,iDAIvB,CAAC;AAEH,eAAO,IAAI,cAAc,uDAIvB,CAAC;AAEH,eAAO,IAAI,aAAa,gDAItB,CAAC;AAEH,eAAO,IAAI,SAAS,4CAIlB,CAAC;AAEH,eAAO,IAAI,oBAAoB,wDAI7B,CAAC;AAEH,eAAO,IAAI,uBAAuB,2DAIhC,CAAC;AAEH,eAAO,IAAI,kBAAkB,sDAI3B,C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,CAAC;AAEH,eAAO,IAAI,kBAAkB,sDAI3B,CAAC;AAEH,eAAO,IAAI,mBAAmB,uDAI5B,CAAC;AAEH,eAAO,IAAI,oBAAoB,yDAK7B,CAAC;AAEH,eAAO,IAAI,YAAY,+CAIrB,CAAC;AAEH,eAAO,IAAI,qBAAqB,0DAI9B,CAAC"}
package/dist/error.d.ts CHANGED
@@ -7,25 +7,26 @@ export interface ErrorData<Code extends string, Status extends number> {
7
7
  reason?: string;
8
8
  [key: string]: any;
9
9
  }
10
+ export type ErrorRecordExtension<Code extends string, Status extends number> = <NewCode extends string = Code>(extension?: Partial<ErrorData<NewCode, Status>>) => ErrorRecord<NewCode, Status>;
10
11
  export type ErrorRecord<Code extends string, Status extends number> = {
11
- __typename: 'error';
12
+ object: 'error';
12
13
  data: ErrorData<Code, Status>;
13
14
  toResponse: () => ErrorData<Code, Status> & {
14
- __typename: 'error';
15
+ object: 'error';
15
16
  ok: false;
16
17
  };
17
- } & ((extension?: Partial<ErrorData<Code, Status>>) => ErrorRecord<Code, Status>);
18
+ } & ErrorRecordExtension<Code, Status>;
18
19
  export declare let createError: <Code extends string, Status extends number>(data: ErrorData<Code, Status>) => ErrorRecord<Code, Status>;
19
20
  export declare class ServiceError<InnerError extends ErrorRecord<any, any>> extends Error {
20
21
  private readonly error;
21
- __typename: "ServiceError";
22
+ object: "ServiceError";
22
23
  private _parent;
23
24
  get parent(): Error | null;
24
25
  constructor(error: InnerError);
25
26
  setParent(parent: Error): this;
26
27
  get data(): ErrorData<any, any>;
27
28
  toResponse(): ErrorData<any, any> & {
28
- __typename: "error";
29
+ object: "error";
29
30
  ok: false;
30
31
  };
31
32
  static fromResponse(raw: ErrorData<any, any>): ServiceError<ErrorRecord<any, any>>;
@@ -1 +1 @@
1
- {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS,CAAC,IAAI,SAAS,MAAM,EAAE,MAAM,SAAS,MAAM;IACn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S,MAAM,EAClE,MAAM,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,KAC5B,WAAW,CAAC,IAAI,EAAE,MAAM,CAe1B,CAAC;AAEF,qBAAa,YAAY,CAAC,UAAU,SAAS,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,CAAE,SAAQ,KAAK;IASnE,OAAO,CAAC,QAAQ,CAAC,KAAK;IARlC,MAAM,EAAG,cAAc,CAAU;IAEjC,OAAO,CAAC,OAAO,CAAsB;IAErC,IAAW,MAAM,iBAEhB;gBAE4B,KAAK,EAAE,UAAU;IAI9C,SAAS,CAAC,MAAM,EAAE,KAAK;IAKvB,IAAI,IAAI,wBAEP;IAED,UAAU;gBA5C4C,OAAO;YAAM,KAAK;;IAgDxE,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC;CAO7C;AAED,eAAO,IAAI,cAAc,GAAI,GAAG,GAAG,KAAG,CAAC,IAAI,YAAY,CAAC,GAAG,CAE1D,CAAC"}
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- var e=require("@lowerdeck/case");function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)({}).hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},t.apply(null,arguments)}function r(e){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},r(e)}function o(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(o=function(){return!!e})()}function n(e,t){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},n(e,t)}function s(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}function i(e){var t="function"==typeof Map?new Map:void 0;return i=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,s)}function s(){return function(e,t,r){if(o())return Reflect.construct.apply(null,arguments);var s=[null];s.push.apply(s,t);var i=new(e.bind.apply(e,s));return r&&n(i,r.prototype),i}(e,arguments,r(this).constructor)}return s.prototype=Object.create(e.prototype,{constructor:{value:s,enumerable:!1,writable:!0,configurable:!0}}),n(s,e)},i(e)}var a=function(e){return Object.assign(function(r){return void 0===r&&(r={}),a(t({},e,r))},{__typename:"error",data:e,toResponse:function(){return t({__typename:"error",ok:!1},e)}})},u=/*#__PURE__*/function(e){function t(t){var r;return(r=e.call(this,t.data.message)||this).error=void 0,r.__typename="ServiceError",r._parent=null,r.error=t,r}var r,o;o=e,(r=t).prototype=Object.create(o.prototype),r.prototype.constructor=r,n(r,o);var i,u,c=t.prototype;return c.setParent=function(e){return this._parent=e,this},c.toResponse=function(){return this.error.toResponse()},t.fromResponse=function(e){var r=e;return delete r.ok,delete r.__typename,new t(a(r))},i=t,(u=[{key:"parent",get:function(){return this._parent}},{key:"data",get:function(){return this.error.data}}])&&function(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,s(o.key),o)}}(i.prototype,u),Object.defineProperty(i,"prototype",{writable:!1}),i}(/*#__PURE__*/i(Error)),c=a({status:500,code:"internal_server_error",message:"An internal server error occurred."}),d=a({status:400,code:"bad_request",message:"The request is invalid."}),p=a({status:401,code:"unauthorized",message:"You are not authorized to access this resource.",hint:"Make sure you are logged in and have the correct permissions to access this resource."}),l=a({status:403,code:"forbidden",message:"You do not have permission to access this resource."}),f=a({status:400,code:"invalid_version",message:"The endpoint does not support the requested version."}),y=a({status:409,code:"conflict",message:"A similar resource already exists."}),m=a({status:410,code:"gone",message:"The requested resource is no longer available."}),h=a({status:402,code:"payment_required",message:"Payment is required to access this resource."}),v=a({status:412,code:"precondition_failed",message:"The precondition of the request failed."}),g=a({status:406,code:"not_acceptable",message:"The requested resource is not acceptable."}),b=a({status:501,code:"not_implemented",message:"The requested resource is not implemented."}),_=a({status:429,code:"too_many_requests",message:"You have made too many requests in a short period of time.",hint:"Please wait a moment and try again."}),E=a({status:504,code:"timeout",message:"The request timed out."}),x=a({status:405,code:"method_not_allowed",message:"The requested method is not allowed for this resource."});exports.ServiceError=u,exports.badRequestError=d,exports.conflictError=y,exports.createError=a,exports.forbiddenError=l,exports.goneError=m,exports.internalServerError=c,exports.invalidVersion=f,exports.isServiceError=function(e){return"ServiceError"===(null==e?void 0:e.__typename)||"ErrorRecord"===(null==e?void 0:e.__typename)},exports.methodNotAllowedError=x,exports.notAcceptableError=g,exports.notFoundError=function(r,o){var n="string"==typeof r?r:r.entity,s="string"==typeof r?o:r.id;return a(t({status:404,code:"not_found",message:"The requested "+e.Cases.toKebabCase(n)+" could not be found.",hint:"Make sure the resource you are trying to access exists, that you have access to it and that it has not been deleted.",entity:n,id:null!=s?s:void 0},"string"==typeof r?{}:r))},exports.notImplementedError=b,exports.paymentRequiredError=h,exports.preconditionFailedError=v,exports.timeoutError=E,exports.tooManyRequestsError=_,exports.unauthorizedError=p,exports.validationError=function(e){return a(t({status:400,code:"invalid_data",message:"The provided data is invalid.",hint:"Make sure the data you are sending follows the specification outlined in the documentation."},e))};
1
+ var e=require("@lowerdeck/case");function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)({}).hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},t.apply(null,arguments)}function r(e){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},r(e)}function o(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(o=function(){return!!e})()}function n(e,t){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},n(e,t)}function s(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}function i(e){var t="function"==typeof Map?new Map:void 0;return i=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,s)}function s(){return function(e,t,r){if(o())return Reflect.construct.apply(null,arguments);var s=[null];s.push.apply(s,t);var i=new(e.bind.apply(e,s));return r&&n(i,r.prototype),i}(e,arguments,r(this).constructor)}return s.prototype=Object.create(e.prototype,{constructor:{value:s,enumerable:!1,writable:!0,configurable:!0}}),n(s,e)},i(e)}var a=function(e){return Object.assign(function(r){return void 0===r&&(r={}),a(t({},e,r))},{object:"error",data:e,toResponse:function(){return t({object:"error",ok:!1},e)}})},u=/*#__PURE__*/function(e){function t(t){var r;return(r=e.call(this,t.data.message)||this).error=void 0,r.object="ServiceError",r._parent=null,r.error=t,r}var r,o;o=e,(r=t).prototype=Object.create(o.prototype),r.prototype.constructor=r,n(r,o);var i,u,c=t.prototype;return c.setParent=function(e){return this._parent=e,this},c.toResponse=function(){return this.error.toResponse()},t.fromResponse=function(e){var r=e;return delete r.ok,delete r.object,new t(a(r))},i=t,(u=[{key:"parent",get:function(){return this._parent}},{key:"data",get:function(){return this.error.data}}])&&function(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,s(o.key),o)}}(i.prototype,u),Object.defineProperty(i,"prototype",{writable:!1}),i}(/*#__PURE__*/i(Error)),c=a({status:500,code:"internal_server_error",message:"An internal server error occurred."}),d=a({status:400,code:"bad_request",message:"The request is invalid."}),p=a({status:401,code:"unauthorized",message:"You are not authorized to access this resource.",hint:"Make sure you are logged in and have the correct permissions to access this resource."}),l=a({status:403,code:"forbidden",message:"You do not have permission to access this resource."}),f=a({status:400,code:"invalid_version",message:"The endpoint does not support the requested version."}),h=a({status:409,code:"conflict",message:"A similar resource already exists."}),v=a({status:410,code:"gone",message:"The requested resource is no longer available."}),y=a({status:402,code:"payment_required",message:"Payment is required to access this resource."}),m=a({status:412,code:"precondition_failed",message:"The precondition of the request failed."}),b=a({status:406,code:"not_acceptable",message:"The requested resource is not acceptable."}),g=a({status:501,code:"not_implemented",message:"The requested resource is not implemented."}),_=a({status:429,code:"too_many_requests",message:"You have made too many requests in a short period of time.",hint:"Please wait a moment and try again."}),E=a({status:504,code:"timeout",message:"The request timed out."}),x=a({status:405,code:"method_not_allowed",message:"The requested method is not allowed for this resource."});exports.ServiceError=u,exports.badRequestError=d,exports.conflictError=h,exports.createError=a,exports.forbiddenError=l,exports.goneError=v,exports.internalServerError=c,exports.invalidVersion=f,exports.isServiceError=function(e){return"ServiceError"===(null==e?void 0:e.object)||"ErrorRecord"===(null==e?void 0:e.object)},exports.methodNotAllowedError=x,exports.notAcceptableError=b,exports.notFoundError=function(r,o){var n="string"==typeof r?r:r.entity,s="string"==typeof r?o:r.id;return a(t({status:404,code:"not_found",message:"The requested "+e.Cases.toKebabCase(n)+" could not be found.",hint:"Make sure the resource you are trying to access exists, that you have access to it and that it has not been deleted.",entity:n,id:null!=s?s:void 0},"string"==typeof r?{}:r))},exports.notImplementedError=g,exports.paymentRequiredError=y,exports.preconditionFailedError=m,exports.timeoutError=E,exports.tooManyRequestsError=_,exports.unauthorizedError=p,exports.validationError=function(e){return a(t({status:400,code:"invalid_data",message:"The provided data is invalid.",hint:"Make sure the data you are sending follows the specification outlined in the documentation."},e))};
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/error.ts","../src/defaultErrors.ts"],"sourcesContent":["export interface ErrorData<Code extends string, Status extends number> {\n status: Status;\n code: Code;\n message: string;\n hint?: string;\n description?: string;\n reason?: string;\n [key: string]: any;\n}\n\nexport type ErrorRecord<Code extends string, Status extends number> = {\n __typename: 'error';\n data: ErrorData<Code, Status>;\n toResponse: () => ErrorData<Code, Status> & { __typename: 'error'; ok: false };\n} & ((extension?: Partial<ErrorData<Code, Status>>) => ErrorRecord<Code, Status>);\n\nexport let createError = <Code extends string, Status extends number>(\n data: ErrorData<Code, Status>\n): ErrorRecord<Code, Status> => {\n return Object.assign(\n (extension: Partial<ErrorData<Code, Status>> = {}): ErrorRecord<Code, Status> =>\n createError({\n ...data,\n ...extension\n }),\n {\n __typename: 'error' as const,\n data,\n toResponse: () => ({ __typename: 'error' as const, ok: false as const, ...data })\n }\n );\n};\n\nexport class ServiceError<InnerError extends ErrorRecord<any, any>> extends Error {\n __typename = 'ServiceError' as const;\n\n private _parent: Error | null = null;\n\n public get parent() {\n return this._parent;\n }\n\n constructor(private readonly error: InnerError) {\n super(error.data.message);\n }\n\n setParent(parent: Error) {\n this._parent = parent;\n return this;\n }\n\n get data() {\n return this.error.data;\n }\n\n toResponse() {\n return this.error.toResponse();\n }\n\n static fromResponse(raw: ErrorData<any, any>) {\n let data = raw;\n delete data.ok;\n delete data.__typename;\n\n return new ServiceError(createError(data));\n }\n}\n\nexport let isServiceError = (e: any): e is ServiceError<any> => {\n return e?.__typename === 'ServiceError' || e?.__typename === 'ErrorRecord';\n};\n","import { Cases } from '@lowerdeck/case';\nimport { ValidationError } from '@lowerdeck/validation';\nimport { ErrorData, createError } from './error';\n\nexport let validationError = (\n d: { errors: ValidationError[]; entity: string } & Partial<ErrorData<'invalid_data', 400>>\n) =>\n createError({\n status: 400,\n code: 'invalid_data',\n message: 'The provided data is invalid.',\n hint: 'Make sure the data you are sending follows the specification outlined in the documentation.',\n ...d\n });\n\nexport let internalServerError = createError({\n status: 500,\n code: 'internal_server_error',\n message: 'An internal server error occurred.'\n});\n\nexport let badRequestError = createError({\n status: 400,\n code: 'bad_request',\n message: 'The request is invalid.'\n});\n\nexport function notFoundError(p1: { entity: string; id?: string } & Partial<ErrorData<'not_found', 404>>): ReturnType<typeof createError>;\nexport function notFoundError(p1: string, p2?: string | null): ReturnType<typeof createError>;\nexport function notFoundError(p1: any, p2?: any): ReturnType<typeof createError> {\n let entity = typeof p1 == 'string' ? p1 : p1.entity;\n let id = typeof p1 == 'string' ? p2 : p1.id;\n\n return createError({\n status: 404,\n code: 'not_found',\n message: `The requested ${Cases.toKebabCase(entity)} could not be found.`,\n hint: 'Make sure the resource you are trying to access exists, that you have access to it and that it has not been deleted.',\n entity,\n id: id ?? undefined,\n\n ...(typeof p1 == 'string' ? {} : p1)\n });\n}\n\nexport let unauthorizedError = createError({\n status: 401,\n code: 'unauthorized',\n message: 'You are not authorized to access this resource.',\n hint: 'Make sure you are logged in and have the correct permissions to access this resource.'\n});\n\nexport let forbiddenError = createError({\n status: 403,\n code: 'forbidden',\n message: 'You do not have permission to access this resource.'\n});\n\nexport let invalidVersion = createError({\n status: 400,\n code: 'invalid_version',\n message: 'The endpoint does not support the requested version.'\n});\n\nexport let conflictError = createError({\n status: 409,\n code: 'conflict',\n message: 'A similar resource already exists.'\n});\n\nexport let goneError = createError({\n status: 410,\n code: 'gone',\n message: 'The requested resource is no longer available.'\n});\n\nexport let paymentRequiredError = createError({\n status: 402,\n code: 'payment_required',\n message: 'Payment is required to access this resource.'\n});\n\nexport let preconditionFailedError = createError({\n status: 412,\n code: 'precondition_failed',\n message: 'The precondition of the request failed.'\n});\n\nexport let notAcceptableError = createError({\n status: 406,\n code: 'not_acceptable',\n message: 'The requested resource is not acceptable.'\n});\n\nexport let notImplementedError = createError({\n status: 501,\n code: 'not_implemented',\n message: 'The requested resource is not implemented.'\n});\n\nexport let tooManyRequestsError = createError({\n status: 429,\n code: 'too_many_requests',\n message: 'You have made too many requests in a short period of time.',\n hint: 'Please wait a moment and try again.'\n});\n\nexport let timeoutError = createError({\n status: 504,\n code: 'timeout',\n message: 'The request timed out.'\n});\n\nexport let methodNotAllowedError = createError({\n status: 405,\n code: 'method_not_allowed',\n message: 'The requested method is not allowed for this resource.'\n});\n"],"names":["createError","data","Object","assign","extension","_extends","__typename","toResponse","ok","ServiceError","_Error","error","_this","call","message","_parent","_proto","prototype","_createClass","setParent","parent","this","fromResponse","raw","key","get","_wrapNativeSuper","Error","internalServerError","status","code","badRequestError","unauthorizedError","hint","forbiddenError","invalidVersion","conflictError","goneError","paymentRequiredError","preconditionFailedError","notAcceptableError","notImplementedError","tooManyRequestsError","timeoutError","methodNotAllowedError","e","p1","p2","entity","id","Cases","toKebabCase","undefined","d"],"mappings":"gnDAgBW,IAAAA,EAAc,SACvBC,GAEA,OAAOC,OAAOC,OACZ,SAACC,GACC,YADDA,IAAAA,IAAAA,EAA8C,CAAA,GAC7CJ,EAAWK,EAAA,CAAA,EACNJ,EACAG,GACH,EACJ,CACEE,WAAY,QACZL,KAAAA,EACAM,WAAY,WAAFF,OAAAA,EAAWC,CAAAA,WAAY,QAAkBE,IAAI,GAAmBP,EAAI,GAGpF,EAEaQ,eAAuDC,SAAAA,GASlE,SAAAD,EAA6BE,GAAiB,IAAAC,EAAA,OAC5CA,EAAAF,EAAAG,KAAMF,KAAAA,EAAMV,KAAKa,UAASF,MADCD,aAAAC,EAR7BN,WAAa,eAAuBM,EAE5BG,QAAwB,KAMHH,EAAKD,MAALA,EAAiBC,CAE9C,WAACF,KAAAD,iFAAAO,EAAAP,EAAAQ,UAqBAC,OArBAF,EAEDG,UAAA,SAAUC,GAER,OADAC,KAAKN,QAAUK,EACRC,IACT,EAACL,EAMDT,WAAA,WACE,OAAWc,KAACV,MAAMJ,YACpB,EAACE,EAEMa,aAAP,SAAoBC,GAClB,IAAItB,EAAOsB,EAIX,cAHOtB,EAAKO,UACLP,EAAKK,WAEL,IAAIG,EAAaT,EAAYC,GACtC,IAACQ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WAChD,8FCzC8BwC,EAASC,GACrC,IAAIC,EAAsB,iBAANF,EAAiBA,EAAKA,EAAGE,OACzCC,EAAkB,iBAANH,EAAiBC,EAAKD,EAAGG,GAEzC,OAAOjD,EAAWK,EAChBwB,CAAAA,OAAQ,IACRC,KAAM,YACNhB,QAAO,iBAAmBoC,QAAMC,YAAYH,GAAO,uBACnDf,KAAM,uHACNe,OAAAA,EACAC,GAAM,MAAFA,EAAAA,OAAMG,GAEO,iBAANN,EAAiB,CAAA,EAAKA,GAErC,2MAvC6B,SAC3BO,UAEArD,EAAWK,EACTwB,CAAAA,OAAQ,IACRC,KAAM,eACNhB,QAAS,gCACTmB,KAAM,+FACHoB,GACH"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/error.ts","../src/defaultErrors.ts"],"sourcesContent":["export interface ErrorData<Code extends string, Status extends number> {\n status: Status;\n code: Code;\n message: string;\n hint?: string;\n description?: string;\n reason?: string;\n [key: string]: any;\n}\n\nexport type ErrorRecordExtension<Code extends string, Status extends number> = <\n NewCode extends string = Code\n>(\n extension?: Partial<ErrorData<NewCode, Status>>\n) => ErrorRecord<NewCode, Status>;\n\nexport type ErrorRecord<Code extends string, Status extends number> = {\n object: 'error';\n data: ErrorData<Code, Status>;\n toResponse: () => ErrorData<Code, Status> & { object: 'error'; ok: false };\n} & ErrorRecordExtension<Code, Status>;\n\nexport let createError = <Code extends string, Status extends number>(\n data: ErrorData<Code, Status>\n): ErrorRecord<Code, Status> => {\n return Object.assign(\n <NewCode extends string = Code>(\n extension: Partial<ErrorData<NewCode, Status>> = {}\n ): ErrorRecord<NewCode, Status> =>\n createError({\n ...data,\n ...extension\n }) as any,\n {\n object: 'error' as const,\n data,\n toResponse: () => ({ object: 'error' as const, ok: false as const, ...data })\n }\n ) as any;\n};\n\nexport class ServiceError<InnerError extends ErrorRecord<any, any>> extends Error {\n object = 'ServiceError' as const;\n\n private _parent: Error | null = null;\n\n public get parent() {\n return this._parent;\n }\n\n constructor(private readonly error: InnerError) {\n super(error.data.message);\n }\n\n setParent(parent: Error) {\n this._parent = parent;\n return this;\n }\n\n get data() {\n return this.error.data;\n }\n\n toResponse() {\n return this.error.toResponse();\n }\n\n static fromResponse(raw: ErrorData<any, any>) {\n let data = raw;\n delete data.ok;\n delete data.object;\n\n return new ServiceError(createError(data));\n }\n}\n\nexport let isServiceError = (e: any): e is ServiceError<any> => {\n return e?.object === 'ServiceError' || e?.object === 'ErrorRecord';\n};\n","import { Cases } from '@lowerdeck/case';\nimport { ValidationError } from '@lowerdeck/validation';\nimport { ErrorData, createError } from './error';\n\nexport let validationError = (\n d: { errors: ValidationError[]; entity: string } & Partial<ErrorData<'invalid_data', 400>>\n) =>\n createError({\n status: 400,\n code: 'invalid_data',\n message: 'The provided data is invalid.',\n hint: 'Make sure the data you are sending follows the specification outlined in the documentation.',\n ...d\n });\n\nexport let internalServerError = createError({\n status: 500,\n code: 'internal_server_error',\n message: 'An internal server error occurred.'\n});\n\nexport let badRequestError = createError({\n status: 400,\n code: 'bad_request',\n message: 'The request is invalid.'\n});\n\nexport function notFoundError(\n p1: { entity: string; id?: string } & Partial<ErrorData<'not_found', 404>>\n): ReturnType<typeof createError>;\nexport function notFoundError(p1: string, p2?: string | null): ReturnType<typeof createError>;\nexport function notFoundError(p1: any, p2?: any): ReturnType<typeof createError> {\n let entity = typeof p1 == 'string' ? p1 : p1.entity;\n let id = typeof p1 == 'string' ? p2 : p1.id;\n\n return createError({\n status: 404,\n code: 'not_found',\n message: `The requested ${Cases.toKebabCase(entity)} could not be found.`,\n hint: 'Make sure the resource you are trying to access exists, that you have access to it and that it has not been deleted.',\n entity,\n id: id ?? undefined,\n\n ...(typeof p1 == 'string' ? {} : p1)\n });\n}\n\nexport let unauthorizedError = createError({\n status: 401,\n code: 'unauthorized',\n message: 'You are not authorized to access this resource.',\n hint: 'Make sure you are logged in and have the correct permissions to access this resource.'\n});\n\nexport let forbiddenError = createError({\n status: 403,\n code: 'forbidden',\n message: 'You do not have permission to access this resource.'\n});\n\nexport let invalidVersion = createError({\n status: 400,\n code: 'invalid_version',\n message: 'The endpoint does not support the requested version.'\n});\n\nexport let conflictError = createError({\n status: 409,\n code: 'conflict',\n message: 'A similar resource already exists.'\n});\n\nexport let goneError = createError({\n status: 410,\n code: 'gone',\n message: 'The requested resource is no longer available.'\n});\n\nexport let paymentRequiredError = createError({\n status: 402,\n code: 'payment_required',\n message: 'Payment is required to access this resource.'\n});\n\nexport let preconditionFailedError = createError({\n status: 412,\n code: 'precondition_failed',\n message: 'The precondition of the request failed.'\n});\n\nexport let notAcceptableError = createError({\n status: 406,\n code: 'not_acceptable',\n message: 'The requested resource is not acceptable.'\n});\n\nexport let notImplementedError = createError({\n status: 501,\n code: 'not_implemented',\n message: 'The requested resource is not implemented.'\n});\n\nexport let tooManyRequestsError = createError({\n status: 429,\n code: 'too_many_requests',\n message: 'You have made too many requests in a short period of time.',\n hint: 'Please wait a moment and try again.'\n});\n\nexport let timeoutError = createError({\n status: 504,\n code: 'timeout',\n message: 'The request timed out.'\n});\n\nexport let methodNotAllowedError = createError({\n status: 405,\n code: 'method_not_allowed',\n message: 'The requested method is not allowed for this resource.'\n});\n"],"names":["createError","data","Object","assign","extension","_extends","object","toResponse","ok","ServiceError","_Error","error","_this","call","message","_parent","_proto","prototype","_createClass","setParent","parent","this","fromResponse","raw","key","get","_wrapNativeSuper","Error","internalServerError","status","code","badRequestError","unauthorizedError","hint","forbiddenError","invalidVersion","conflictError","goneError","paymentRequiredError","preconditionFailedError","notAcceptableError","notImplementedError","tooManyRequestsError","timeoutError","methodNotAllowedError","e","p1","p2","entity","id","Cases","toKebabCase","undefined","d"],"mappings":"gnDAsBW,IAAAA,EAAc,SACvBC,GAEA,OAAOC,OAAOC,OACZ,SACEC,GAEA,YAFAA,IAAAA,IAAAA,EAAiD,CAAA,GAEjDJ,EAAWK,EAAA,CAAA,EACNJ,EACAG,GACI,EACX,CACEE,OAAQ,QACRL,KAAAA,EACAM,WAAY,WAAFF,OAAAA,EA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RC,KAAM,mBACNhB,QAAS,iDAGAyB,EAA0BvC,EAAY,CAC/C6B,OAAQ,IACRC,KAAM,sBACNhB,QAAS,4CAGA0B,EAAqBxC,EAAY,CAC1C6B,OAAQ,IACRC,KAAM,iBACNhB,QAAS,8CAGA2B,EAAsBzC,EAAY,CAC3C6B,OAAQ,IACRC,KAAM,kBACNhB,QAAS,+CAGA4B,EAAuB1C,EAAY,CAC5C6B,OAAQ,IACRC,KAAM,oBACNhB,QAAS,6DACTmB,KAAM,wCAGGU,EAAe3C,EAAY,CACpC6B,OAAQ,IACRC,KAAM,UACNhB,QAAS,2BAGA8B,EAAwB5C,EAAY,CAC7C6B,OAAQ,IACRC,KAAM,qBACNhB,QAAS,qRD1CiB,SAAC+B,GAC3B,MAAqB,kBAAdA,MAAAA,OAAAA,EAAAA,EAAGvC,SAA2C,uBAAduC,SAAAA,EAAGvC,OAC5C,8FC/C8BwC,EAASC,GACrC,IAAIC,EAAsB,iBAANF,EAAiBA,EAAKA,EAAGE,OACzCC,EAAkB,iBAANH,EAAiBC,EAAKD,EAAGG,GAEzC,OAAOjD,EAAWK,EAChBwB,CAAAA,OAAQ,IACRC,KAAM,YACNhB,QAAO,iBAAmBoC,QAAMC,YAAYH,GAAO,uBACnDf,KAAM,uHACNe,OAAAA,EACAC,GAAM,MAAFA,EAAAA,OAAMG,GAEO,iBAANN,EAAiB,CAAA,EAAKA,GAErC,2MAzC6B,SAC3BO,UAEArD,EAAWK,EACTwB,CAAAA,OAAQ,IACRC,KAAM,eACNhB,QAAS,gCACTmB,KAAM,+FACHoB,GACH"}
@@ -1,2 +1,2 @@
1
- import{Cases as e}from"@lowerdeck/case";function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)({}).hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},t.apply(null,arguments)}function r(e){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},r(e)}function o(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(o=function(){return!!e})()}function n(e,t){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},n(e,t)}function s(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}function a(e){var t="function"==typeof Map?new Map:void 0;return a=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,s)}function s(){return function(e,t,r){if(o())return Reflect.construct.apply(null,arguments);var s=[null];s.push.apply(s,t);var a=new(e.bind.apply(e,s));return r&&n(a,r.prototype),a}(e,arguments,r(this).constructor)}return s.prototype=Object.create(e.prototype,{constructor:{value:s,enumerable:!1,writable:!0,configurable:!0}}),n(s,e)},a(e)}var i=function(e){return Object.assign(function(r){return void 0===r&&(r={}),i(t({},e,r))},{__typename:"error",data:e,toResponse:function(){return t({__typename:"error",ok:!1},e)}})},u=/*#__PURE__*/function(e){function t(t){var r;return(r=e.call(this,t.data.message)||this).error=void 0,r.__typename="ServiceError",r._parent=null,r.error=t,r}var r,o;o=e,(r=t).prototype=Object.create(o.prototype),r.prototype.constructor=r,n(r,o);var a,u,c=t.prototype;return c.setParent=function(e){return this._parent=e,this},c.toResponse=function(){return this.error.toResponse()},t.fromResponse=function(e){var r=e;return delete r.ok,delete r.__typename,new t(i(r))},a=t,(u=[{key:"parent",get:function(){return this._parent}},{key:"data",get:function(){return this.error.data}}])&&function(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,s(o.key),o)}}(a.prototype,u),Object.defineProperty(a,"prototype",{writable:!1}),a}(/*#__PURE__*/a(Error)),c=function(e){return"ServiceError"===(null==e?void 0:e.__typename)||"ErrorRecord"===(null==e?void 0:e.__typename)},d=function(e){return i(t({status:400,code:"invalid_data",message:"The provided data is invalid.",hint:"Make sure the data you are sending follows the specification outlined in the documentation."},e))},p=i({status:500,code:"internal_server_error",message:"An internal server error occurred."}),l=i({status:400,code:"bad_request",message:"The request is invalid."});function f(r,o){var n="string"==typeof r?r:r.entity,s="string"==typeof r?o:r.id;return i(t({status:404,code:"not_found",message:"The requested "+e.toKebabCase(n)+" could not be found.",hint:"Make sure the resource you are trying to access exists, that you have access to it and that it has not been deleted.",entity:n,id:null!=s?s:void 0},"string"==typeof r?{}:r))}var y=i({status:401,code:"unauthorized",message:"You are not authorized to access this resource.",hint:"Make sure you are logged in and have the correct permissions to access this resource."}),h=i({status:403,code:"forbidden",message:"You do not have permission to access this resource."}),m=i({status:400,code:"invalid_version",message:"The endpoint does not support the requested version."}),v=i({status:409,code:"conflict",message:"A similar resource already exists."}),g=i({status:410,code:"gone",message:"The requested resource is no longer available."}),b=i({status:402,code:"payment_required",message:"Payment is required to access this resource."}),_=i({status:412,code:"precondition_failed",message:"The precondition of the request failed."}),O=i({status:406,code:"not_acceptable",message:"The requested resource is not acceptable."}),w=i({status:501,code:"not_implemented",message:"The requested resource is not implemented."}),j=i({status:429,code:"too_many_requests",message:"You have made too many requests in a short period of time.",hint:"Please wait a moment and try again."}),q=i({status:504,code:"timeout",message:"The request timed out."}),P=i({status:405,code:"method_not_allowed",message:"The requested method is not allowed for this resource."});export{u as ServiceError,l as badRequestError,v as conflictError,i as createError,h as forbiddenError,g as goneError,p as internalServerError,m as invalidVersion,c as isServiceError,P as methodNotAllowedError,O as notAcceptableError,f as notFoundError,w as notImplementedError,b as paymentRequiredError,_ as preconditionFailedError,q as timeoutError,j as tooManyRequestsError,y as unauthorizedError,d as validationError};
1
+ import{Cases as e}from"@lowerdeck/case";function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)({}).hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},t.apply(null,arguments)}function r(e){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},r(e)}function o(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(o=function(){return!!e})()}function n(e,t){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},n(e,t)}function s(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}function a(e){var t="function"==typeof Map?new Map:void 0;return a=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,s)}function s(){return function(e,t,r){if(o())return Reflect.construct.apply(null,arguments);var s=[null];s.push.apply(s,t);var a=new(e.bind.apply(e,s));return r&&n(a,r.prototype),a}(e,arguments,r(this).constructor)}return s.prototype=Object.create(e.prototype,{constructor:{value:s,enumerable:!1,writable:!0,configurable:!0}}),n(s,e)},a(e)}var i=function(e){return Object.assign(function(r){return void 0===r&&(r={}),i(t({},e,r))},{object:"error",data:e,toResponse:function(){return t({object:"error",ok:!1},e)}})},u=/*#__PURE__*/function(e){function t(t){var r;return(r=e.call(this,t.data.message)||this).error=void 0,r.object="ServiceError",r._parent=null,r.error=t,r}var r,o;o=e,(r=t).prototype=Object.create(o.prototype),r.prototype.constructor=r,n(r,o);var a,u,c=t.prototype;return c.setParent=function(e){return this._parent=e,this},c.toResponse=function(){return this.error.toResponse()},t.fromResponse=function(e){var r=e;return delete r.ok,delete r.object,new t(i(r))},a=t,(u=[{key:"parent",get:function(){return this._parent}},{key:"data",get:function(){return this.error.data}}])&&function(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,s(o.key),o)}}(a.prototype,u),Object.defineProperty(a,"prototype",{writable:!1}),a}(/*#__PURE__*/a(Error)),c=function(e){return"ServiceError"===(null==e?void 0:e.object)||"ErrorRecord"===(null==e?void 0:e.object)},d=function(e){return i(t({status:400,code:"invalid_data",message:"The provided data is invalid.",hint:"Make sure the data you are sending follows the specification outlined in the documentation."},e))},l=i({status:500,code:"internal_server_error",message:"An internal server error occurred."}),f=i({status:400,code:"bad_request",message:"The request is invalid."});function p(r,o){var n="string"==typeof r?r:r.entity,s="string"==typeof r?o:r.id;return i(t({status:404,code:"not_found",message:"The requested "+e.toKebabCase(n)+" could not be found.",hint:"Make sure the resource you are trying to access exists, that you have access to it and that it has not been deleted.",entity:n,id:null!=s?s:void 0},"string"==typeof r?{}:r))}var h=i({status:401,code:"unauthorized",message:"You are not authorized to access this resource.",hint:"Make sure you are logged in and have the correct permissions to access this resource."}),y=i({status:403,code:"forbidden",message:"You do not have permission to access this resource."}),v=i({status:400,code:"invalid_version",message:"The endpoint does not support the requested version."}),m=i({status:409,code:"conflict",message:"A similar resource already exists."}),b=i({status:410,code:"gone",message:"The requested resource is no longer available."}),g=i({status:402,code:"payment_required",message:"Payment is required to access this resource."}),_=i({status:412,code:"precondition_failed",message:"The precondition of the request failed."}),j=i({status:406,code:"not_acceptable",message:"The requested resource is not acceptable."}),O=i({status:501,code:"not_implemented",message:"The requested resource is not implemented."}),w=i({status:429,code:"too_many_requests",message:"You have made too many requests in a short period of time.",hint:"Please wait a moment and try again."}),q=i({status:504,code:"timeout",message:"The request timed out."}),P=i({status:405,code:"method_not_allowed",message:"The requested method is not allowed for this resource."});export{u as ServiceError,f as badRequestError,m as conflictError,i as createError,y as forbiddenError,b as goneError,l as internalServerError,v as invalidVersion,c as isServiceError,P as methodNotAllowedError,j as notAcceptableError,p as notFoundError,O as notImplementedError,g as paymentRequiredError,_ as preconditionFailedError,q as timeoutError,w as tooManyRequestsError,h as unauthorizedError,d as validationError};
2
2
  //# sourceMappingURL=index.module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.module.js","sources":["../src/error.ts","../src/defaultErrors.ts"],"sourcesContent":["export interface ErrorData<Code extends string, Status extends number> {\n status: Status;\n code: Code;\n message: string;\n hint?: string;\n description?: string;\n reason?: string;\n [key: string]: any;\n}\n\nexport type ErrorRecord<Code extends string, Status extends number> = {\n __typename: 'error';\n data: ErrorData<Code, Status>;\n toResponse: () => ErrorData<Code, Status> & { __typename: 'error'; ok: false };\n} & ((extension?: Partial<ErrorData<Code, Status>>) => ErrorRecord<Code, Status>);\n\nexport let createError = <Code extends string, Status extends number>(\n data: ErrorData<Code, Status>\n): ErrorRecord<Code, Status> => {\n return Object.assign(\n (extension: Partial<ErrorData<Code, Status>> = {}): ErrorRecord<Code, Status> =>\n createError({\n ...data,\n ...extension\n }),\n {\n __typename: 'error' as const,\n data,\n toResponse: () => ({ __typename: 'error' as const, ok: false as const, ...data })\n }\n );\n};\n\nexport class ServiceError<InnerError extends ErrorRecord<any, any>> extends Error {\n __typename = 'ServiceError' as const;\n\n private _parent: Error | null = null;\n\n public get parent() {\n return this._parent;\n }\n\n constructor(private readonly error: InnerError) {\n super(error.data.message);\n }\n\n setParent(parent: Error) {\n this._parent = parent;\n return this;\n }\n\n get data() {\n return this.error.data;\n }\n\n toResponse() {\n return this.error.toResponse();\n }\n\n static fromResponse(raw: ErrorData<any, any>) {\n let data = raw;\n delete data.ok;\n delete data.__typename;\n\n return new ServiceError(createError(data));\n }\n}\n\nexport let isServiceError = (e: any): e is ServiceError<any> => {\n return e?.__typename === 'ServiceError' || e?.__typename === 'ErrorRecord';\n};\n","import { Cases } from '@lowerdeck/case';\nimport { ValidationError } from '@lowerdeck/validation';\nimport { ErrorData, createError } from './error';\n\nexport let validationError = (\n d: { errors: ValidationError[]; entity: string } & Partial<ErrorData<'invalid_data', 400>>\n) =>\n createError({\n status: 400,\n code: 'invalid_data',\n message: 'The provided data is invalid.',\n hint: 'Make sure the data you are sending follows the specification outlined in the documentation.',\n ...d\n });\n\nexport let internalServerError = createError({\n status: 500,\n code: 'internal_server_error',\n message: 'An internal server error occurred.'\n});\n\nexport let badRequestError = createError({\n status: 400,\n code: 'bad_request',\n message: 'The request is invalid.'\n});\n\nexport function notFoundError(p1: { entity: string; id?: string } & Partial<ErrorData<'not_found', 404>>): ReturnType<typeof createError>;\nexport function notFoundError(p1: string, p2?: string | null): ReturnType<typeof createError>;\nexport function notFoundError(p1: any, p2?: any): ReturnType<typeof createError> {\n let entity = typeof p1 == 'string' ? p1 : p1.entity;\n let id = typeof p1 == 'string' ? p2 : p1.id;\n\n return createError({\n status: 404,\n code: 'not_found',\n message: `The requested ${Cases.toKebabCase(entity)} could not be found.`,\n hint: 'Make sure the resource you are trying to access exists, that you have access to it and that it has not been deleted.',\n entity,\n id: id ?? undefined,\n\n ...(typeof p1 == 'string' ? {} : p1)\n });\n}\n\nexport let unauthorizedError = createError({\n status: 401,\n code: 'unauthorized',\n message: 'You are not authorized to access this resource.',\n hint: 'Make sure you are logged in and have the correct permissions to access this resource.'\n});\n\nexport let forbiddenError = createError({\n status: 403,\n code: 'forbidden',\n message: 'You do not have permission to access this resource.'\n});\n\nexport let invalidVersion = createError({\n status: 400,\n code: 'invalid_version',\n message: 'The endpoint does not support the requested version.'\n});\n\nexport let conflictError = createError({\n status: 409,\n code: 'conflict',\n message: 'A similar resource already exists.'\n});\n\nexport let goneError = createError({\n status: 410,\n code: 'gone',\n message: 'The requested resource is no longer available.'\n});\n\nexport let paymentRequiredError = createError({\n status: 402,\n code: 'payment_required',\n message: 'Payment is required to access this resource.'\n});\n\nexport let preconditionFailedError = createError({\n status: 412,\n code: 'precondition_failed',\n message: 'The precondition of the request failed.'\n});\n\nexport let notAcceptableError = createError({\n status: 406,\n code: 'not_acceptable',\n message: 'The requested resource is not acceptable.'\n});\n\nexport let notImplementedError = createError({\n status: 501,\n code: 'not_implemented',\n message: 'The requested resource is not implemented.'\n});\n\nexport let tooManyRequestsError = createError({\n status: 429,\n code: 'too_many_requests',\n message: 'You have made too many requests in a short period of time.',\n hint: 'Please wait a moment and try again.'\n});\n\nexport let timeoutError = createError({\n status: 504,\n code: 'timeout',\n message: 'The request timed out.'\n});\n\nexport let methodNotAllowedError = createError({\n status: 405,\n code: 'method_not_allowed',\n message: 'The requested method is not allowed for this resource.'\n});\n"],"names":["createError","data","Object","assign","extension","_extends","__typename","toResponse","ok","ServiceError","_Error","error","_this","call","message","_parent","_proto","prototype","_createClass","setParent","parent","this","fromResponse","raw","key","get","_wrapNativeSuper","Error","isServiceError","e","validationError","d","status","code","hint","internalServerError","badRequestError","notFoundError","p1","p2","entity","id","Cases","toKebabCase","undefined","unauthorizedError","forbiddenError","invalidVersion","conflictError","goneError","paymentRequiredError","preconditionFailedError","notAcceptableError","notImplementedError","tooManyRequestsError","timeoutError","methodNotAllowedError"],"mappings":"unDAgBW,IAAAA,EAAc,SACvBC,GAEA,OAAOC,OAAOC,OACZ,SAACC,GACC,YADDA,IAAAA,IAAAA,EAA8C,CAAA,GAC7CJ,EAAWK,EAAA,CAAA,EACNJ,EACAG,GACH,EACJ,CACEE,WAAY,QACZL,KAAAA,EACAM,WAAY,WAAFF,OAAAA,EAAWC,CAAAA,WAAY,QAAkBE,IAAI,GAAmBP,EAAI,GAGpF,EAEaQ,eAAuDC,SAAAA,GASlE,SAAAD,EAA6BE,GAAiB,IAAAC,EAAA,OAC5CA,EAAAF,EAAAG,KAAMF,KAAAA,EAAMV,KAAKa,UAASF,MADCD,aAAAC,EAR7BN,WAAa,eAAuBM,EAE5BG,QAAwB,KAMHH,EAAKD,MAALA,EAAiBC,CAE9C,WAACF,KAAAD,iFAAAO,EAAAP,EAAAQ,UAq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wDAGAiC,EAAiB/C,EAAY,CACtCgC,OAAQ,IACRC,KAAM,kBACNnB,QAAS,yDAGAkC,EAAgBhD,EAAY,CACrCgC,OAAQ,IACRC,KAAM,WACNnB,QAAS,uCAGAmC,EAAYjD,EAAY,CACjCgC,OAAQ,IACRC,KAAM,OACNnB,QAAS,mDAGAoC,EAAuBlD,EAAY,CAC5CgC,OAAQ,IACRC,KAAM,mBACNnB,QAAS,iDAGAqC,EAA0BnD,EAAY,CAC/CgC,OAAQ,IACRC,KAAM,sBACNnB,QAAS,4CAGAsC,EAAqBpD,EAAY,CAC1CgC,OAAQ,IACRC,KAAM,iBACNnB,QAAS,8CAGAuC,EAAsBrD,EAAY,CAC3CgC,OAAQ,IACRC,KAAM,kBACNnB,QAAS,+CAGAwC,EAAuBtD,EAAY,CAC5CgC,OAAQ,IACRC,KAAM,oBACNnB,QAAS,6DACToB,KAAM,wCAGGqB,EAAevD,EAAY,CACpCgC,OAAQ,IACRC,KAAM,UACNnB,QAAS,2BAGA0C,EAAwBxD,EAAY,CAC7CgC,OAAQ,IACRC,KAAM,qBACNnB,QAAS"}
1
+ {"version":3,"file":"index.module.js","sources":["../src/error.ts","../src/defaultErrors.ts"],"sourcesContent":["export interface ErrorData<Code extends string, Status extends number> {\n status: Status;\n code: Code;\n message: string;\n hint?: string;\n description?: string;\n reason?: string;\n [key: string]: any;\n}\n\nexport type ErrorRecordExtension<Code extends string, Status extends number> = <\n NewCode extends string = Code\n>(\n extension?: Partial<ErrorData<NewCode, Status>>\n) => ErrorRecord<NewCode, Status>;\n\nexport type ErrorRecord<Code extends string, Status extends number> = {\n object: 'error';\n data: ErrorData<Code, Status>;\n toResponse: () => ErrorData<Code, Status> & { object: 'error'; ok: false };\n} & ErrorRecordExtension<Code, Status>;\n\nexport let createError = <Code extends string, Status extends number>(\n data: ErrorData<Code, Status>\n): ErrorRecord<Code, Status> => {\n return Object.assign(\n <NewCode extends string = Code>(\n extension: Partial<ErrorData<NewCode, Status>> = {}\n ): ErrorRecord<NewCode, Status> =>\n createError({\n ...data,\n ...extension\n }) as any,\n {\n object: 'error' as const,\n data,\n toResponse: () => ({ object: 'error' as const, ok: false as const, ...data })\n }\n ) as any;\n};\n\nexport class ServiceError<InnerError extends ErrorRecord<any, any>> extends Error {\n object = 'ServiceError' as const;\n\n private _parent: Error | null = null;\n\n public get parent() {\n return this._parent;\n }\n\n constructor(private readonly error: InnerError) {\n super(error.data.message);\n }\n\n setParent(parent: Error) {\n this._parent = parent;\n return this;\n }\n\n get data() {\n return this.error.data;\n }\n\n toResponse() {\n return this.error.toResponse();\n }\n\n static fromResponse(raw: ErrorData<any, any>) {\n let data = raw;\n delete data.ok;\n delete data.object;\n\n return new ServiceError(createError(data));\n }\n}\n\nexport let isServiceError = (e: any): e is ServiceError<any> => {\n return e?.object === 'ServiceError' || e?.object === 'ErrorRecord';\n};\n","import { Cases } from '@lowerdeck/case';\nimport { ValidationError } from '@lowerdeck/validation';\nimport { ErrorData, createError } from './error';\n\nexport let validationError = (\n d: { errors: ValidationError[]; entity: string } & Partial<ErrorData<'invalid_data', 400>>\n) =>\n createError({\n status: 400,\n code: 'invalid_data',\n message: 'The provided data is invalid.',\n hint: 'Make sure the data you are sending follows the specification outlined in the documentation.',\n ...d\n });\n\nexport let internalServerError = createError({\n status: 500,\n code: 'internal_server_error',\n message: 'An internal server error occurred.'\n});\n\nexport let badRequestError = createError({\n status: 400,\n code: 'bad_request',\n message: 'The request is invalid.'\n});\n\nexport function notFoundError(\n p1: { entity: string; id?: string } & Partial<ErrorData<'not_found', 404>>\n): ReturnType<typeof createError>;\nexport function notFoundError(p1: string, p2?: string | null): ReturnType<typeof createError>;\nexport function notFoundError(p1: any, p2?: any): ReturnType<typeof createError> {\n let entity = typeof p1 == 'string' ? p1 : p1.entity;\n let id = typeof p1 == 'string' ? p2 : p1.id;\n\n return createError({\n status: 404,\n code: 'not_found',\n message: `The requested ${Cases.toKebabCase(entity)} could not be found.`,\n hint: 'Make sure the resource you are trying to access exists, that you have access to it and that it has not been deleted.',\n entity,\n id: id ?? undefined,\n\n ...(typeof p1 == 'string' ? {} : p1)\n });\n}\n\nexport let unauthorizedError = createError({\n status: 401,\n code: 'unauthorized',\n message: 'You are not authorized to access this resource.',\n hint: 'Make sure you are logged in and have the correct permissions to access this resource.'\n});\n\nexport let forbiddenError = createError({\n status: 403,\n code: 'forbidden',\n message: 'You do not have permission to access this resource.'\n});\n\nexport let invalidVersion = createError({\n status: 400,\n code: 'invalid_version',\n message: 'The endpoint does not support the requested version.'\n});\n\nexport let conflictError = createError({\n status: 409,\n code: 'conflict',\n message: 'A similar resource already exists.'\n});\n\nexport let goneError = createError({\n status: 410,\n code: 'gone',\n message: 'The requested resource is no longer available.'\n});\n\nexport let paymentRequiredError = createError({\n status: 402,\n code: 'payment_required',\n message: 'Payment is required to access this resource.'\n});\n\nexport let preconditionFailedError = createError({\n status: 412,\n code: 'precondition_failed',\n message: 'The precondition of the request failed.'\n});\n\nexport let notAcceptableError = createError({\n status: 406,\n code: 'not_acceptable',\n message: 'The requested resource is not acceptable.'\n});\n\nexport let notImplementedError = createError({\n status: 501,\n code: 'not_implemented',\n message: 'The requested resource is not implemented.'\n});\n\nexport let tooManyRequestsError = createError({\n status: 429,\n code: 'too_many_requests',\n message: 'You have made too many requests in a short period of time.',\n hint: 'Please wait a moment and try again.'\n});\n\nexport let timeoutError = createError({\n status: 504,\n code: 'timeout',\n message: 'The request timed out.'\n});\n\nexport let methodNotAllowedError = createError({\n status: 405,\n code: 'method_not_allowed',\n message: 'The requested method is not allowed for this resource.'\n});\n"],"names":["createError","data","Object","assign","extension","_extends","object","toResponse","ok","ServiceError","_Error","error","_this","call","message","_parent","_proto","prototype","_createClass","setParent","parent","this","fromResponse","raw","key","get","_wrapNativeSuper","Error","isServiceError","e","validationError","d","status","code","hint","internalServerError","badRequestError","notFoundError","p1","p2","entity","id","Cases","toKebabCase","undefined","unauthorizedError","forbiddenError","invalidVersion","conflictError","goneError","paymentRequiredError","preconditionFailedError","notAcceptableError","notImplementedError","tooManyRequestsError","timeoutError","methodNotAllowedError"],"mappings":"unDAsBW,IAAAA,EAAc,SACvBC,GAEA,OAAOC,OAAOC,OACZ,SACEC,GAEA,YAFAA,IAAAA,IAAAA,EAAiD,CAAA,GAEjDJ,EAAWK,EAAA,CAAA,EACNJ,EACAG,GACI,EACX,CACEE,OAAQ,QACRL,KAAAA,EACAM,WAAY,WAAFF,OAAAA,EAAWC,CAAAA,OAAQ,QAAkBE,IAAI,GAAmBP,EAAI,GAGhF,EAEaQ,eAAuDC,SAAAA,GASlE,SAAAD,EAA6BE,GAAiB,IAAAC,EAAA,OAC5CA,EAAAF,EAAAG,KAAMF,KAAAA,EAAMV,KAAKa,UAASF,MADCD,aAAAC,EAR7BN,OAAS,eAAuBM,EAExBG,QAAwB,KAMHH,EAAKD,MAALA,EAAiBC,CAE9C,WAACF,KAAAD,iFAAAO,EAAAP,EAAAQ,UAqBAC,OArBAF,EAEDG,UAAA,SAAUC,GAER,OADAC,KAAKN,QAAUK,EACRC,IACT,EAACL,EAMDT,WAAA,WACE,OAAWc,KAACV,MAAMJ,YACpB,EAACE,EAEMa,aAAP,SAAoBC,GAClB,IAAItB,EAAOsB,EAIX,cAHOtB,EAAKO,UACLP,EAAKK,OAEL,IAAIG,EAAaT,EAAYC,GACtC,IAACQ,OAAAe,IAAA,SAAAC,IA3BD,WACE,OAAWJ,KAACN,OACd,GAACS,CAAAA,IAAAC,OAAAA,IAWD,WACE,OAAOJ,KAAKV,MAAMV,IACpB,iPAACyB,CApBiEhB,cAoBjEgB,EApByEC,QAmCjEC,EAAiB,SAACC,GAC3B,MAAqB,kBAAdA,MAAAA,OAAAA,EAAAA,EAAGvB,SAA2C,uBAAduB,SAAAA,EAAGvB,OAC5C,EC1EWwB,EAAkB,SAC3BC,UAEA/B,EAAWK,EACT2B,CAAAA,OAAQ,IACRC,KAAM,eACNnB,QAAS,gCACToB,KAAM,+FACHH,GACH,EAEOI,EAAsBnC,EAAY,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,OAAQ,IACRC,KAAM,qBACNnB,QAAS"}
package/dist/index.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@lowerdeck/case")):"function"==typeof define&&define.amd?define(["exports","@lowerdeck/case"],t):t((e||self).error={},e._case)}(this,function(e,t){function r(){return r=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)({}).hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},r.apply(null,arguments)}function o(e){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},o(e)}function n(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(n=function(){return!!e})()}function s(e,t){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},s(e,t)}function i(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}function a(e){var t="function"==typeof Map?new Map:void 0;return a=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return function(e,t,r){if(n())return Reflect.construct.apply(null,arguments);var o=[null];o.push.apply(o,t);var i=new(e.bind.apply(e,o));return r&&s(i,r.prototype),i}(e,arguments,o(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),s(r,e)},a(e)}var u=function(e){return Object.assign(function(t){return void 0===t&&(t={}),u(r({},e,t))},{__typename:"error",data:e,toResponse:function(){return r({__typename:"error",ok:!1},e)}})},c=/*#__PURE__*/function(e){function t(t){var r;return(r=e.call(this,t.data.message)||this).error=void 0,r.__typename="ServiceError",r._parent=null,r.error=t,r}var r,o;o=e,(r=t).prototype=Object.create(o.prototype),r.prototype.constructor=r,s(r,o);var n,a,c=t.prototype;return c.setParent=function(e){return this._parent=e,this},c.toResponse=function(){return this.error.toResponse()},t.fromResponse=function(e){var r=e;return delete r.ok,delete r.__typename,new t(u(r))},n=t,(a=[{key:"parent",get:function(){return this._parent}},{key:"data",get:function(){return this.error.data}}])&&function(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,i(o.key),o)}}(n.prototype,a),Object.defineProperty(n,"prototype",{writable:!1}),n}(/*#__PURE__*/a(Error)),d=u({status:500,code:"internal_server_error",message:"An internal server error occurred."}),l=u({status:400,code:"bad_request",message:"The request is invalid."}),p=u({status:401,code:"unauthorized",message:"You are not authorized to access this resource.",hint:"Make sure you are logged in and have the correct permissions to access this resource."}),f=u({status:403,code:"forbidden",message:"You do not have permission to access this resource."}),y=u({status:400,code:"invalid_version",message:"The endpoint does not support the requested version."}),h=u({status:409,code:"conflict",message:"A similar resource already exists."}),m=u({status:410,code:"gone",message:"The requested resource is no longer available."}),v=u({status:402,code:"payment_required",message:"Payment is required to access this resource."}),g=u({status:412,code:"precondition_failed",message:"The precondition of the request failed."}),b=u({status:406,code:"not_acceptable",message:"The requested resource is not acceptable."}),_=u({status:501,code:"not_implemented",message:"The requested resource is not implemented."}),E=u({status:429,code:"too_many_requests",message:"You have made too many requests in a short period of time.",hint:"Please wait a moment and try again."}),O=u({status:504,code:"timeout",message:"The request timed out."}),q=u({status:405,code:"method_not_allowed",message:"The requested method is not allowed for this resource."});e.ServiceError=c,e.badRequestError=l,e.conflictError=h,e.createError=u,e.forbiddenError=f,e.goneError=m,e.internalServerError=d,e.invalidVersion=y,e.isServiceError=function(e){return"ServiceError"===(null==e?void 0:e.__typename)||"ErrorRecord"===(null==e?void 0:e.__typename)},e.methodNotAllowedError=q,e.notAcceptableError=b,e.notFoundError=function(e,o){var n="string"==typeof e?e:e.entity,s="string"==typeof e?o:e.id;return u(r({status:404,code:"not_found",message:"The requested "+t.Cases.toKebabCase(n)+" could not be found.",hint:"Make sure the resource you are trying to access exists, that you have access to it and that it has not been deleted.",entity:n,id:null!=s?s:void 0},"string"==typeof e?{}:e))},e.notImplementedError=_,e.paymentRequiredError=v,e.preconditionFailedError=g,e.timeoutError=O,e.tooManyRequestsError=E,e.unauthorizedError=p,e.validationError=function(e){return u(r({status:400,code:"invalid_data",message:"The provided data is invalid.",hint:"Make sure the data you are sending follows the specification outlined in the documentation."},e))}});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@lowerdeck/case")):"function"==typeof define&&define.amd?define(["exports","@lowerdeck/case"],t):t((e||self).error={},e._case)}(this,function(e,t){function r(){return r=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)({}).hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},r.apply(null,arguments)}function o(e){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},o(e)}function n(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(n=function(){return!!e})()}function s(e,t){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},s(e,t)}function i(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}function a(e){var t="function"==typeof Map?new Map:void 0;return a=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return function(e,t,r){if(n())return Reflect.construct.apply(null,arguments);var o=[null];o.push.apply(o,t);var i=new(e.bind.apply(e,o));return r&&s(i,r.prototype),i}(e,arguments,o(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),s(r,e)},a(e)}var u=function(e){return Object.assign(function(t){return void 0===t&&(t={}),u(r({},e,t))},{object:"error",data:e,toResponse:function(){return r({object:"error",ok:!1},e)}})},c=/*#__PURE__*/function(e){function t(t){var r;return(r=e.call(this,t.data.message)||this).error=void 0,r.object="ServiceError",r._parent=null,r.error=t,r}var r,o;o=e,(r=t).prototype=Object.create(o.prototype),r.prototype.constructor=r,s(r,o);var n,a,c=t.prototype;return c.setParent=function(e){return this._parent=e,this},c.toResponse=function(){return this.error.toResponse()},t.fromResponse=function(e){var r=e;return delete r.ok,delete r.object,new t(u(r))},n=t,(a=[{key:"parent",get:function(){return this._parent}},{key:"data",get:function(){return this.error.data}}])&&function(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,i(o.key),o)}}(n.prototype,a),Object.defineProperty(n,"prototype",{writable:!1}),n}(/*#__PURE__*/a(Error)),d=u({status:500,code:"internal_server_error",message:"An internal server error occurred."}),l=u({status:400,code:"bad_request",message:"The request is invalid."}),f=u({status:401,code:"unauthorized",message:"You are not authorized to access this resource.",hint:"Make sure you are logged in and have the correct permissions to access this resource."}),p=u({status:403,code:"forbidden",message:"You do not have permission to access this resource."}),h=u({status:400,code:"invalid_version",message:"The endpoint does not support the requested version."}),y=u({status:409,code:"conflict",message:"A similar resource already exists."}),m=u({status:410,code:"gone",message:"The requested resource is no longer available."}),v=u({status:402,code:"payment_required",message:"Payment is required to access this resource."}),b=u({status:412,code:"precondition_failed",message:"The precondition of the request failed."}),g=u({status:406,code:"not_acceptable",message:"The requested resource is not acceptable."}),_=u({status:501,code:"not_implemented",message:"The requested resource is not implemented."}),E=u({status:429,code:"too_many_requests",message:"You have made too many requests in a short period of time.",hint:"Please wait a moment and try again."}),j=u({status:504,code:"timeout",message:"The request timed out."}),O=u({status:405,code:"method_not_allowed",message:"The requested method is not allowed for this resource."});e.ServiceError=c,e.badRequestError=l,e.conflictError=y,e.createError=u,e.forbiddenError=p,e.goneError=m,e.internalServerError=d,e.invalidVersion=h,e.isServiceError=function(e){return"ServiceError"===(null==e?void 0:e.object)||"ErrorRecord"===(null==e?void 0:e.object)},e.methodNotAllowedError=O,e.notAcceptableError=g,e.notFoundError=function(e,o){var n="string"==typeof e?e:e.entity,s="string"==typeof e?o:e.id;return u(r({status:404,code:"not_found",message:"The requested "+t.Cases.toKebabCase(n)+" could not be found.",hint:"Make sure the resource you are trying to access exists, that you have access to it and that it has not been deleted.",entity:n,id:null!=s?s:void 0},"string"==typeof e?{}:e))},e.notImplementedError=_,e.paymentRequiredError=v,e.preconditionFailedError=b,e.timeoutError=j,e.tooManyRequestsError=E,e.unauthorizedError=f,e.validationError=function(e){return u(r({status:400,code:"invalid_data",message:"The provided data is invalid.",hint:"Make sure the data you are sending follows the specification outlined in the documentation."},e))}});
2
2
  //# sourceMappingURL=index.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/error.ts","../src/defaultErrors.ts"],"sourcesContent":["export interface ErrorData<Code extends string, Status extends number> {\n status: Status;\n code: Code;\n message: string;\n hint?: string;\n description?: string;\n reason?: string;\n [key: string]: any;\n}\n\nexport type ErrorRecord<Code extends string, Status extends number> = {\n __typename: 'error';\n data: ErrorData<Code, Status>;\n toResponse: () => ErrorData<Code, Status> & { __typename: 'error'; ok: false };\n} & ((extension?: Partial<ErrorData<Code, Status>>) => ErrorRecord<Code, Status>);\n\nexport let createError = <Code extends string, Status extends number>(\n data: ErrorData<Code, Status>\n): ErrorRecord<Code, Status> => {\n return Object.assign(\n (extension: Partial<ErrorData<Code, Status>> = {}): ErrorRecord<Code, Status> =>\n createError({\n ...data,\n ...extension\n }),\n {\n __typename: 'error' as const,\n data,\n toResponse: () => ({ __typename: 'error' as const, ok: false as const, ...data })\n }\n );\n};\n\nexport class ServiceError<InnerError extends ErrorRecord<any, any>> extends Error {\n __typename = 'ServiceError' as const;\n\n private _parent: Error | null = null;\n\n public get parent() {\n return this._parent;\n }\n\n constructor(private readonly error: InnerError) {\n super(error.data.message);\n }\n\n setParent(parent: Error) {\n this._parent = parent;\n return this;\n }\n\n get data() {\n return this.error.data;\n }\n\n toResponse() {\n return this.error.toResponse();\n }\n\n static fromResponse(raw: ErrorData<any, any>) {\n let data = raw;\n delete data.ok;\n delete data.__typename;\n\n return new ServiceError(createError(data));\n }\n}\n\nexport let isServiceError = (e: any): e is ServiceError<any> => {\n return e?.__typename === 'ServiceError' || e?.__typename === 'ErrorRecord';\n};\n","import { Cases } from '@lowerdeck/case';\nimport { ValidationError } from '@lowerdeck/validation';\nimport { ErrorData, createError } from './error';\n\nexport let validationError = (\n d: { errors: ValidationError[]; entity: string } & Partial<ErrorData<'invalid_data', 400>>\n) =>\n createError({\n status: 400,\n code: 'invalid_data',\n message: 'The provided data is invalid.',\n hint: 'Make sure the data you are sending follows the specification outlined in the documentation.',\n ...d\n });\n\nexport let internalServerError = createError({\n status: 500,\n code: 'internal_server_error',\n message: 'An internal server error occurred.'\n});\n\nexport let badRequestError = createError({\n status: 400,\n code: 'bad_request',\n message: 'The request is invalid.'\n});\n\nexport function notFoundError(p1: { entity: string; id?: string } & Partial<ErrorData<'not_found', 404>>): ReturnType<typeof createError>;\nexport function notFoundError(p1: string, p2?: string | null): ReturnType<typeof createError>;\nexport function notFoundError(p1: any, p2?: any): ReturnType<typeof createError> {\n let entity = typeof p1 == 'string' ? p1 : p1.entity;\n let id = typeof p1 == 'string' ? p2 : p1.id;\n\n return createError({\n status: 404,\n code: 'not_found',\n message: `The requested ${Cases.toKebabCase(entity)} could not be found.`,\n hint: 'Make sure the resource you are trying to access exists, that you have access to it and that it has not been deleted.',\n entity,\n id: id ?? undefined,\n\n ...(typeof p1 == 'string' ? {} : p1)\n });\n}\n\nexport let unauthorizedError = createError({\n status: 401,\n code: 'unauthorized',\n message: 'You are not authorized to access this resource.',\n hint: 'Make sure you are logged in and have the correct permissions to access this resource.'\n});\n\nexport let forbiddenError = createError({\n status: 403,\n code: 'forbidden',\n message: 'You do not have permission to access this resource.'\n});\n\nexport let invalidVersion = createError({\n status: 400,\n code: 'invalid_version',\n message: 'The endpoint does not support the requested version.'\n});\n\nexport let conflictError = createError({\n status: 409,\n code: 'conflict',\n message: 'A similar resource already exists.'\n});\n\nexport let goneError = createError({\n status: 410,\n code: 'gone',\n message: 'The requested resource is no longer available.'\n});\n\nexport let paymentRequiredError = createError({\n status: 402,\n code: 'payment_required',\n message: 'Payment is required to access this resource.'\n});\n\nexport let preconditionFailedError = createError({\n status: 412,\n code: 'precondition_failed',\n message: 'The precondition of the request failed.'\n});\n\nexport let notAcceptableError = createError({\n status: 406,\n code: 'not_acceptable',\n message: 'The requested resource is not acceptable.'\n});\n\nexport let notImplementedError = createError({\n status: 501,\n code: 'not_implemented',\n message: 'The requested resource is not implemented.'\n});\n\nexport let tooManyRequestsError = createError({\n status: 429,\n code: 'too_many_requests',\n message: 'You have made too many requests in a short period of time.',\n hint: 'Please wait a moment and try again.'\n});\n\nexport let timeoutError = createError({\n status: 504,\n code: 'timeout',\n message: 'The request timed out.'\n});\n\nexport let methodNotAllowedError = createError({\n status: 405,\n code: 'method_not_allowed',\n message: 'The requested method is not allowed for this resource.'\n});\n"],"names":["createError","data","Object","assign","extension","_extends","__typename","toResponse","ok","ServiceError","_Error","error","_this","call","message","_parent","_proto","prototype","_createClass","setParent","parent","this","fromResponse","raw","key","get","_wrapNativeSuper","Error","internalServerError","status","code","badRequestError","unauthorizedError","hint","forbiddenError","invalidVersion","conflictError","goneError","paymentRequiredError","preconditionFailedError","notAcceptableError","notImplementedError","tooManyRequestsError","timeoutError","methodNot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oB,GACH"}
1
+ {"version":3,"file":"index.umd.js","sources":["../src/error.ts","../src/defaultErrors.ts"],"sourcesContent":["export interface ErrorData<Code extends string, Status extends number> {\n status: Status;\n code: Code;\n message: string;\n hint?: string;\n description?: string;\n reason?: string;\n [key: string]: any;\n}\n\nexport type ErrorRecordExtension<Code extends string, Status extends number> = <\n NewCode extends string = Code\n>(\n extension?: Partial<ErrorData<NewCode, Status>>\n) => ErrorRecord<NewCode, Status>;\n\nexport type ErrorRecord<Code extends string, Status extends number> = {\n object: 'error';\n data: ErrorData<Code, Status>;\n toResponse: () => ErrorData<Code, Status> & { object: 'error'; ok: false };\n} & ErrorRecordExtension<Code, Status>;\n\nexport let createError = <Code extends string, Status extends number>(\n data: ErrorData<Code, Status>\n): ErrorRecord<Code, Status> => {\n return Object.assign(\n <NewCode extends string = Code>(\n extension: Partial<ErrorData<NewCode, Status>> = {}\n ): ErrorRecord<NewCode, Status> =>\n createError({\n ...data,\n ...extension\n }) as any,\n {\n object: 'error' as const,\n data,\n toResponse: () => ({ object: 'error' as const, ok: false as const, ...data })\n }\n ) as any;\n};\n\nexport class ServiceError<InnerError extends ErrorRecord<any, any>> extends Error {\n object = 'ServiceError' as const;\n\n private _parent: Error | null = null;\n\n public get parent() {\n return this._parent;\n }\n\n constructor(private readonly error: InnerError) {\n super(error.data.message);\n }\n\n setParent(parent: Error) {\n this._parent = parent;\n return this;\n }\n\n get data() {\n return this.error.data;\n }\n\n toResponse() {\n return this.error.toResponse();\n }\n\n static fromResponse(raw: ErrorData<any, any>) {\n let data = raw;\n delete data.ok;\n delete data.object;\n\n return new ServiceError(createError(data));\n }\n}\n\nexport let isServiceError = (e: any): e is ServiceError<any> => {\n return e?.object === 'ServiceError' || e?.object === 'ErrorRecord';\n};\n","import { Cases } from '@lowerdeck/case';\nimport { ValidationError } from '@lowerdeck/validation';\nimport { ErrorData, createError } from './error';\n\nexport let validationError = (\n d: { errors: ValidationError[]; entity: string } & Partial<ErrorData<'invalid_data', 400>>\n) =>\n createError({\n status: 400,\n code: 'invalid_data',\n message: 'The provided data is invalid.',\n hint: 'Make sure the data you are sending follows the specification outlined in the documentation.',\n ...d\n });\n\nexport let internalServerError = createError({\n status: 500,\n code: 'internal_server_error',\n message: 'An internal server error occurred.'\n});\n\nexport let badRequestError = createError({\n status: 400,\n code: 'bad_request',\n message: 'The request is invalid.'\n});\n\nexport function notFoundError(\n p1: { entity: string; id?: string } & Partial<ErrorData<'not_found', 404>>\n): ReturnType<typeof createError>;\nexport function notFoundError(p1: string, p2?: string | null): ReturnType<typeof createError>;\nexport function notFoundError(p1: any, p2?: any): ReturnType<typeof createError> {\n let entity = typeof p1 == 'string' ? p1 : p1.entity;\n let id = typeof p1 == 'string' ? p2 : p1.id;\n\n return createError({\n status: 404,\n code: 'not_found',\n message: `The requested ${Cases.toKebabCase(entity)} could not be found.`,\n hint: 'Make sure the resource you are trying to access exists, that you have access to it and that it has not been deleted.',\n entity,\n id: id ?? undefined,\n\n ...(typeof p1 == 'string' ? {} : p1)\n });\n}\n\nexport let unauthorizedError = createError({\n status: 401,\n code: 'unauthorized',\n message: 'You are not authorized to access this resource.',\n hint: 'Make sure you are logged in and have the correct permissions to access this resource.'\n});\n\nexport let forbiddenError = createError({\n status: 403,\n code: 'forbidden',\n message: 'You do not have permission to access this resource.'\n});\n\nexport let invalidVersion = createError({\n status: 400,\n code: 'invalid_version',\n message: 'The endpoint does not support the requested version.'\n});\n\nexport let conflictError = createError({\n status: 409,\n code: 'conflict',\n message: 'A similar resource already exists.'\n});\n\nexport let goneError = createError({\n status: 410,\n code: 'gone',\n message: 'The requested resource is no longer available.'\n});\n\nexport let paymentRequiredError = createError({\n status: 402,\n code: 'payment_required',\n message: 'Payment is required to access this resource.'\n});\n\nexport let preconditionFailedError = createError({\n status: 412,\n code: 'precondition_failed',\n message: 'The precondition of the request failed.'\n});\n\nexport let notAcceptableError = createError({\n status: 406,\n code: 'not_acceptable',\n message: 'The requested resource is not acceptable.'\n});\n\nexport let notImplementedError = createError({\n status: 501,\n code: 'not_implemented',\n message: 'The requested resource is not implemented.'\n});\n\nexport let tooManyRequestsError = createError({\n status: 429,\n code: 'too_many_requests',\n message: 'You have made too many requests in a short period of time.',\n hint: 'Please wait a moment and try again.'\n});\n\nexport let timeoutError = createError({\n status: 504,\n code: 'timeout',\n message: 'The request timed out.'\n});\n\nexport let methodNotAllowedError = createError({\n status: 405,\n code: 'method_not_allowed',\n message: 'The requested method is not allowed for this resource.'\n});\n"],"names":["createError","data","Object","assign","extension","_extends","object","toResponse","ok","ServiceError","_Error","error","_this","call","message","_parent","_proto","prototype","_createClass","setParent","parent","this","fromResponse","raw","key","get","_wrapNativeSuper","Error","internalServerError","status","code","badRequestError","unauthorizedError","hint","forbiddenError","invalidVersion","conflictError","goneError","paymentRequiredError","preconditionFailedError","notAcceptableError","notImplementedError","tooManyRequestsError","timeoutError","methodNotAllowedError","e","p1","p2","entity","id","Cases","toKebabCase","undefined","d"],"mappings":"q2DAsBW,IAAAA,EAAc,SACvBC,GAEA,OAAOC,OAAOC,OACZ,SACEC,GAEA,YAFAA,IAAAA,IAAAA,EAAiD,CAAA,GAEjDJ,EAAWK,EAAA,CAAA,EACNJ,EACAG,GACI,EACX,CACEE,OAAQ,QACRL,KAAAA,EACAM,WAAY,WAAFF,OAAAA,EAAWC,CAAAA,OAAQ,QAAkBE,IAAI,GAAmBP,EAAI,GAGhF,EAEaQ,eAAuDC,SAAAA,GASlE,SAAAD,EAA6BE,GAAiB,IAAAC,EAAA,OAC5CA,EAAAF,EAAAG,KAAMF,KAAAA,EAAMV,KAAKa,UAASF,MADCD,aAAAC,EAR7BN,OAAS,eAAuBM,EAExBG,QAAwB,KAMHH,EAAKD,MAALA,EAAiBC,CAE9C,WAACF,KAAAD,iFAAAO,EAAAP,EAAAQ,UAqBAC,OArBAF,EAEDG,UAAA,SAAUC,GAER,OADAC,KAAKN,QAAUK,EACRC,IACT,EAACL,EAMDT,WAAA,WACE,OAAWc,KAACV,MAAMJ,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RC,KAAM,qBACNhB,QAAS,+ND1CiB,SAAC+B,GAC3B,MAAqB,kBAAdA,MAAAA,OAAAA,EAAAA,EAAGvC,SAA2C,uBAAduC,SAAAA,EAAGvC,OAC5C,4EC/C8BwC,EAASC,GACrC,IAAIC,EAAsB,iBAANF,EAAiBA,EAAKA,EAAGE,OACzCC,EAAkB,iBAANH,EAAiBC,EAAKD,EAAGG,GAEzC,OAAOjD,EAAWK,EAChBwB,CAAAA,OAAQ,IACRC,KAAM,YACNhB,QAAO,iBAAmBoC,QAAMC,YAAYH,GAAO,uBACnDf,KAAM,uHACNe,OAAAA,EACAC,GAAM,MAAFA,EAAAA,OAAMG,GAEO,iBAANN,EAAiB,CAAA,EAAKA,GAErC,iKAzC6B,SAC3BO,UAEArD,EAAWK,EACTwB,CAAAA,OAAQ,IACRC,KAAM,eACNhB,QAAS,gCACTmB,KAAM,+FACHoB,GACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowerdeck/error",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -25,7 +25,9 @@ export let badRequestError = createError({
25
25
  message: 'The request is invalid.'
26
26
  });
27
27
 
28
- export function notFoundError(p1: { entity: string; id?: string } & Partial<ErrorData<'not_found', 404>>): ReturnType<typeof createError>;
28
+ export function notFoundError(
29
+ p1: { entity: string; id?: string } & Partial<ErrorData<'not_found', 404>>
30
+ ): ReturnType<typeof createError>;
29
31
  export function notFoundError(p1: string, p2?: string | null): ReturnType<typeof createError>;
30
32
  export function notFoundError(p1: any, p2?: any): ReturnType<typeof createError> {
31
33
  let entity = typeof p1 == 'string' ? p1 : p1.entity;
package/src/error.test.ts CHANGED
@@ -20,7 +20,7 @@ describe('createError', () => {
20
20
  };
21
21
  let errorRecord = createError(data);
22
22
  let response = errorRecord.toResponse();
23
- expect(response).toEqual({ ...data, __typename: 'error', ok: false });
23
+ expect(response).toEqual({ ...data, object: 'error', ok: false });
24
24
  });
25
25
 
26
26
  test('should create an error record with a response function that can be extended', () => {
@@ -33,7 +33,7 @@ describe('createError', () => {
33
33
  let response = errorRecord({ hint: 'This is a hint' }).toResponse();
34
34
  expect(response).toEqual({
35
35
  ...data,
36
- __typename: 'error',
36
+ object: 'error',
37
37
  ok: false,
38
38
  hint: 'This is a hint'
39
39
  });
@@ -69,6 +69,6 @@ describe('ServiceError', () => {
69
69
  });
70
70
  let apiError = new ServiceError(errorRecord);
71
71
  let response = apiError.toResponse();
72
- expect(response).toEqual({ ...errorRecord.data, __typename: 'error', ok: false });
72
+ expect(response).toEqual({ ...errorRecord.data, object: 'error', ok: false });
73
73
  });
74
74
  });
package/src/error.ts CHANGED
@@ -8,31 +8,39 @@ export interface ErrorData<Code extends string, Status extends number> {
8
8
  [key: string]: any;
9
9
  }
10
10
 
11
+ export type ErrorRecordExtension<Code extends string, Status extends number> = <
12
+ NewCode extends string = Code
13
+ >(
14
+ extension?: Partial<ErrorData<NewCode, Status>>
15
+ ) => ErrorRecord<NewCode, Status>;
16
+
11
17
  export type ErrorRecord<Code extends string, Status extends number> = {
12
- __typename: 'error';
18
+ object: 'error';
13
19
  data: ErrorData<Code, Status>;
14
- toResponse: () => ErrorData<Code, Status> & { __typename: 'error'; ok: false };
15
- } & ((extension?: Partial<ErrorData<Code, Status>>) => ErrorRecord<Code, Status>);
20
+ toResponse: () => ErrorData<Code, Status> & { object: 'error'; ok: false };
21
+ } & ErrorRecordExtension<Code, Status>;
16
22
 
17
23
  export let createError = <Code extends string, Status extends number>(
18
24
  data: ErrorData<Code, Status>
19
25
  ): ErrorRecord<Code, Status> => {
20
26
  return Object.assign(
21
- (extension: Partial<ErrorData<Code, Status>> = {}): ErrorRecord<Code, Status> =>
27
+ <NewCode extends string = Code>(
28
+ extension: Partial<ErrorData<NewCode, Status>> = {}
29
+ ): ErrorRecord<NewCode, Status> =>
22
30
  createError({
23
31
  ...data,
24
32
  ...extension
25
- }),
33
+ }) as any,
26
34
  {
27
- __typename: 'error' as const,
35
+ object: 'error' as const,
28
36
  data,
29
- toResponse: () => ({ __typename: 'error' as const, ok: false as const, ...data })
37
+ toResponse: () => ({ object: 'error' as const, ok: false as const, ...data })
30
38
  }
31
- );
39
+ ) as any;
32
40
  };
33
41
 
34
42
  export class ServiceError<InnerError extends ErrorRecord<any, any>> extends Error {
35
- __typename = 'ServiceError' as const;
43
+ object = 'ServiceError' as const;
36
44
 
37
45
  private _parent: Error | null = null;
38
46
 
@@ -60,12 +68,12 @@ export class ServiceError<InnerError extends ErrorRecord<any, any>> extends Erro
60
68
  static fromResponse(raw: ErrorData<any, any>) {
61
69
  let data = raw;
62
70
  delete data.ok;
63
- delete data.__typename;
71
+ delete data.object;
64
72
 
65
73
  return new ServiceError(createError(data));
66
74
  }
67
75
  }
68
76
 
69
77
  export let isServiceError = (e: any): e is ServiceError<any> => {
70
- return e?.__typename === 'ServiceError' || e?.__typename === 'ErrorRecord';
78
+ return e?.object === 'ServiceError' || e?.object === 'ErrorRecord';
71
79
  };