@funkit/api-base 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +3 -1
  3. package/package.json +8 -2
  4. package/.eslintignore +0 -5
  5. package/dist/test/services/assets.test.d.ts +0 -1
  6. package/dist/test/services/assets.test.js +0 -37
  7. package/dist/test/services/assets.test.js.map +0 -1
  8. package/dist/test/services/checkout.test.d.ts +0 -1
  9. package/dist/test/services/checkout.test.js +0 -42
  10. package/dist/test/services/checkout.test.js.map +0 -1
  11. package/dist/test/services/mesh.test.d.ts +0 -1
  12. package/dist/test/services/mesh.test.js +0 -12
  13. package/dist/test/services/mesh.test.js.map +0 -1
  14. package/dist/test/services/moonpay.test.d.ts +0 -1
  15. package/dist/test/services/moonpay.test.js +0 -25
  16. package/dist/test/services/moonpay.test.js.map +0 -1
  17. package/dist/test/setup.d.ts +0 -0
  18. package/dist/test/setup.js +0 -10
  19. package/dist/test/setup.js.map +0 -1
  20. package/index.ts +0 -4
  21. package/src/consts/api.ts +0 -9
  22. package/src/consts/index.ts +0 -3
  23. package/src/consts/request.ts +0 -16
  24. package/src/consts/retry.ts +0 -21
  25. package/src/errors/BaseError.ts +0 -28
  26. package/src/errors/ClientError.ts +0 -175
  27. package/src/errors/ServerError.ts +0 -43
  28. package/src/errors/errors.json +0 -626
  29. package/src/errors/index.ts +0 -4
  30. package/src/errors/types.ts +0 -64
  31. package/src/services/assets/endpoints.ts +0 -131
  32. package/src/services/assets/index.ts +0 -2
  33. package/src/services/assets/types.ts +0 -80
  34. package/src/services/checkout/endpoints.ts +0 -233
  35. package/src/services/checkout/index.ts +0 -2
  36. package/src/services/checkout/types.ts +0 -130
  37. package/src/services/index.ts +0 -4
  38. package/src/services/mesh/endpoints.ts +0 -164
  39. package/src/services/mesh/index.ts +0 -2
  40. package/src/services/mesh/types.ts +0 -63
  41. package/src/services/moonpay/endpoints.ts +0 -62
  42. package/src/services/moonpay/index.ts +0 -2
  43. package/src/services/moonpay/types.ts +0 -15
  44. package/src/utils/checkout.ts +0 -17
  45. package/src/utils/error.ts +0 -15
  46. package/src/utils/index.ts +0 -3
  47. package/src/utils/request.ts +0 -198
  48. package/test/services/assets.test.ts +0 -41
  49. package/test/services/checkout.test.ts +0 -53
  50. package/test/services/mesh.test.ts +0 -10
  51. package/test/services/moonpay.test.ts +0 -24
  52. package/test/setup.ts +0 -9
  53. package/tsconfig.json +0 -33
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @funkit/api-base
2
+
3
+ ## 0.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - bb74a26: tooling: better configurations, add README
package/README.md CHANGED
@@ -1 +1,3 @@
1
- ## FunKit Api Base
1
+ # Funkit Api Base
2
+
3
+ Base APIs for funkit packages
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funkit/api-base",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Base API for Funkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -26,12 +26,18 @@
26
26
  "url": "git+https://github.com/fun-xyz/funkit.git",
27
27
  "directory": "packages/api-base"
28
28
  },
29
+ "files": [
30
+ "dist/src",
31
+ "dist/index.d.ts",
32
+ "dist/index.js",
33
+ "dist/index.js.map",
34
+ "CHANGELOG.md"
35
+ ],
29
36
  "scripts": {
30
37
  "build": "rm -rf dist && tsc",
31
38
  "build:watch": "rm -rf dist && tsc -w",
32
39
  "lint": "eslint --ext .ts,.tsx './**/*.{ts,tsx}'",
33
40
  "lint:fix": "eslint --ext .ts,.tsx './**/*.{ts,tsx}' --fix",
34
- "dev-test": "ts-node ./dev-test.ts",
35
41
  "test": "vitest"
36
42
  }
37
43
  }
package/.eslintignore DELETED
@@ -1,5 +0,0 @@
1
- node_modules
2
- dist
3
- *.js
4
- *.spec.ts
5
- packages/*/dist/**/*
@@ -1 +0,0 @@
1
- export {};
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const __1 = require("../../");
4
- describe('assets service', () => {
5
- test('getAssetPriceInfo returns valid result', async () => {
6
- const assetPriceInfo = await (0, __1.getAssetPriceInfo)({
7
- chainId: '1',
8
- assetTokenAddress: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
9
- apiKey: global.TEST_API_KEY,
10
- });
11
- expect(assetPriceInfo.amount).toBe(1);
12
- expect(assetPriceInfo.unitPrice).toBeGreaterThan(0);
13
- expect(assetPriceInfo.total).toBeGreaterThan(0);
14
- });
15
- test('getAllWalletTokens returns valid result', async () => {
16
- const walletBalance = await (0, __1.getAllWalletTokens)({
17
- walletAddress: global.TEST_WALLET_ADDRESS,
18
- onlyVerifiedTokens: true,
19
- apiKey: global.TEST_API_KEY,
20
- });
21
- expect(walletBalance['1']).toBeTruthy();
22
- expect(walletBalance['137']).toBeTruthy();
23
- expect(walletBalance['8453']).toBeTruthy();
24
- expect(walletBalance['324']).toBeTruthy();
25
- expect(walletBalance['42161']).toBeTruthy();
26
- });
27
- test('getAllWalletTokensByChainId returns valid result', async () => {
28
- const ethereumBalance = await (0, __1.getAllWalletTokensByChainId)({
29
- chainId: '1',
30
- walletAddress: global.TEST_WALLET_ADDRESS,
31
- onlyVerifiedTokens: true,
32
- apiKey: global.TEST_API_KEY,
33
- });
34
- expect(ethereumBalance).toBeTruthy();
35
- });
36
- });
37
- //# sourceMappingURL=assets.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"assets.test.js","sourceRoot":"","sources":["../../../test/services/assets.test.ts"],"names":[],"mappings":";;AAAA,8BAIe;AAEf,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,IAAI,CAAC,wCAAwC,EAAE,KAAK,IAAI,EAAE;QACxD,MAAM,cAAc,GAAG,MAAM,IAAA,qBAAiB,EAAC;YAC7C,OAAO,E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AAC,CAAC,UAAU,EAAE,CAAA;IACtC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const __1 = require("../../");
4
- const QUOTE_TEST_TIMEOUT = 30000; // 30 seconds
5
- describe('checkout service', () => {
6
- let quoteId;
7
- test('getCheckoutQuote and initializeCheckout returns valid result', async () => {
8
- const quoteParams = {
9
- fromChainId: '8453',
10
- fromTokenAddress: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
11
- fromTokenDecimals: 18,
12
- toChainId: '137',
13
- toTokenAddress: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
14
- toTokenDecimals: 18,
15
- toTokenAmount: 5,
16
- expirationTimestampMs: 300000, // 5 minutes
17
- sponsorInitialTransferGasLimit: '0',
18
- recipientAddr: global.TEST_WALLET_ADDRESS,
19
- needsRefuel: false,
20
- apiKey: global.TEST_API_KEY,
21
- };
22
- const quote = await (0, __1.getCheckoutQuote)(quoteParams);
23
- quoteId = quote.quoteId;
24
- expect(quote.quoteId).toBeTruthy();
25
- const checkoutInitParams = {
26
- quoteId,
27
- sourceOfFund: `balance|eoa|${global.TEST_WALLET_ADDRESS}`,
28
- apiKey: global.TEST_API_KEY,
29
- clientMetadata: {},
30
- };
31
- const depositAddr = await (0, __1.initializeCheckout)(checkoutInitParams);
32
- expect(depositAddr).toBeTruthy();
33
- }, QUOTE_TEST_TIMEOUT);
34
- test('getCheckoutsByRecipientAddress returns valid result', async () => {
35
- const checkouts = await (0, __1.getCheckoutsByRecipientAddress)({
36
- recipientAddress: global.TEST_WALLET_ADDRESS,
37
- apiKey: global.TEST_API_KEY,
38
- });
39
- expect(checkouts.length).toBeGreaterThan(0);
40
- });
41
- });
42
- //# sourceMappingURL=checkout.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"check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gB,EAAE,MAAM,CAAC,mBAAmB;YAC5C,MAAM,EAAE,MAAM,CAAC,YAAY;SAC5B,CAAC,CAAA;QACF,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAA;IAC7C,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const __1 = require("../../");
4
- describe('mesh service', () => {
5
- test('meshGetTransferIntegrations returns valid result', async () => {
6
- const integrationsResponse = await (0, __1.meshGetTransferIntegrations)({
7
- apiKey: global.TEST_API_KEY,
8
- });
9
- expect(integrationsResponse.integrations.length).toBeGreaterThan(0);
10
- });
11
- });
12
- //# sourceMappingURL=mesh.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mesh.test.js","sourceRoot":"","sources":["../../../test/services/mesh.test.ts"],"names":[],"mappings":";;AAAA,8BAAoD;AAEpD,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,IAAI,CAAC,kDAAkD,EAAE,KAAK,IAAI,EAAE;QAClE,MAAM,oBAAoB,GAAG,MAAM,IAAA,+BAA2B,EAAC;YAC7D,MAAM,EAAE,MAAM,CAAC,YAAY;SAC5B,CAAC,CAAA;QACF,MAAM,CAAC,oBAAoB,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAA;IACrE,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const __1 = require("../../");
4
- describe('moonpay service', () => {
5
- test('getMoonpayUrlSignature returns valid result', async () => {
6
- const urlSignature = await (0, __1.getMoonpayUrlSignature)({
7
- apiKey: global.TEST_API_KEY,
8
- isSandbox: true,
9
- url: 'https://buy.moonpay.com/?apiKey=pk_test_dWfAhBbvVexIId9S5hPd78mKM7ivIsqu&currencyCode=usdc&walletAddress=0x931122fD30c218e208A3546A3faa2f40F6c06A3e&colorCode=%2331a3f8&theme=light&baseCurrencyCode=usd&quoteCurrencyAmount=106.23&lockAmount=true&externalCustomerId=0x6ec0c2f25d323e7779925Cc20c3740101f990d9F%7C0x6ec0c2f25d323e7779925Cc20c3740101f990d9F%7CgsWiq9zk0W5Rh4vzpqURI6nyauFL0tSm9m0EydTI&mpSdk=%7B%22version%22%3A%221.8.0%22%2C%22environment%22%3A%22production%22%2C%22flow%22%3A%22buy%22%2C%22variant%22%3A%22embedded%22%2C%22platform%22%3A%22web%22%7D',
10
- });
11
- expect(urlSignature).toBeTruthy();
12
- });
13
- test('getMoonpayBuyQuoteForCreditCard returns valid result', async () => {
14
- const buyQuote = await (0, __1.getMoonpayBuyQuoteForCreditCard)({
15
- apiKey: global.TEST_API_KEY,
16
- baseCurrencyCode: 'usd',
17
- currencyCode: 'usdc',
18
- quoteCurrencyAmount: '106.23',
19
- areFeesIncluded: true,
20
- });
21
- expect(buyQuote.accountId).toBeTruthy();
22
- expect(buyQuote.baseCurrencyCode).toBe('usd');
23
- });
24
- });
25
- //# sourceMappingURL=moonpay.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"moonpay.test.js","sourceRoot":"","sources":["../../../test/services/moonpay.test.ts"],"names":[],"mappings":";;AAAA,8BAAgF;AAEhF,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,IAAI,CAAC,6CAA6C,EAAE,KAAK,IAAI,EAAE;QAC7D,MAAM,YAAY,GAAG,MAAM,IAAA,0BAAsB,EAAC;YAChD,MAAM,EAAE,MAAM,CAAC,YAAY;YAC3B,SAAS,EAAE,IAAI;YACf,GAAG,EAAE,ijBAAijB;SACvjB,CAAC,CAAA;QACF,MAAM,CAAC,YAAY,CAAC,CAAC,UAAU,EAAE,CAAA;IACnC,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,sDAAsD,EAAE,KAAK,IAAI,EAAE;QACtE,MAAM,QAAQ,GAAG,MAAM,IAAA,mCAA+B,EAAC;YACrD,MAAM,EAAE,MAAM,CAAC,YAAY;YAC3B,gBAAgB,EAAE,KAAK;YACvB,YAAY,EAAE,MAAM;YACpB,mBAAmB,EAAE,QAAQ;YAC7B,eAAe,EAAE,IAAI;SACtB,CAAC,CAAA;QACF,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,CAAA;QACvC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC/C,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
File without changes
@@ -1,10 +0,0 @@
1
- "use strict";
2
- beforeAll(() => {
3
- global.TEST_API_KEY = 'hnHevQR0y394nBprGrvNx4HgoZHUwMet5mXTOBhf';
4
- global.TEST_WALLET_ADDRESS = '0xD646AF38161B2d9Fd65F5116C7Ecdf23562644b0';
5
- });
6
- afterAll(() => {
7
- delete global.TEST_API_KEY;
8
- delete global.TEST_WALLET_ADDRESS;
9
- });
10
- //# sourceMappingURL=setup.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setup.js","sourceRoot":"","sources":["../../test/setup.ts"],"names":[],"mappings":";AAAA,SAAS,CAAC,GAAG,EAAE;IACb,MAAM,CAAC,YAAY,GAAG,0CAA0C,CAAA;IAChE,MAAM,CAAC,mBAAmB,GAAG,4CAA4C,CAAA;AAC3E,CAAC,CAAC,CAAA;AAEF,QAAQ,CAAC,GAAG,EAAE;IACZ,OAAO,MAAM,CAAC,YAAY,CAAA;IAC1B,OAAO,MAAM,CAAC,mBAAmB,CAAA;AACnC,CAAC,CAAC,CAAA"}
package/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from './src/consts'
2
- export * from './src/errors'
3
- export * from './src/services'
4
- export * from './src/utils'
package/src/consts/api.ts DELETED
@@ -1,9 +0,0 @@
1
- export const API_BASE_URL =
2
- process.env.NODE_ENV === 'staging'
3
- ? 'https://api.fun.xyz/staging/v1'
4
- : process.env.NODE_ENV === 'testing'
5
- ? 'https://api.fun.xyz/testing/v1'
6
- : process.env.NODE_ENV === 'local'
7
- ? 'http://127.0.0.1:3000'
8
- : // Production
9
- 'https://api.fun.xyz/v1'
@@ -1,3 +0,0 @@
1
- export * from './api'
2
- export * from './request'
3
- export * from './retry'
@@ -1,16 +0,0 @@
1
- import { RetryOptions } from './retry'
2
-
3
- export interface BaseRequest {
4
- uri: string
5
- method: 'PUT' | 'DELETE' | 'GET' | 'POST'
6
- apiKey: string
7
- retryOptions?: RetryOptions
8
- body?: object
9
- }
10
-
11
- export type GetRequest = Omit<BaseRequest, 'body' | 'method'>
12
- export type PostRequest = Omit<BaseRequest, 'method'>
13
- export type DeleteRequest = Omit<BaseRequest, 'body' | 'method'>
14
- export type PutRequest = Omit<BaseRequest, 'method'>
15
-
16
- export type BaseResponse = any // TODO:
@@ -1,21 +0,0 @@
1
- import { PartialAttemptOptions } from '@lifeomic/attempt'
2
-
3
- import { errorAbortHandler } from '../utils/error'
4
- import { BaseResponse } from './request'
5
-
6
- export type RetryOptions = PartialAttemptOptions<BaseResponse>
7
-
8
- export const DEFAULT_RETRY_OPTIONS = {
9
- delay: 100,
10
- initialDelay: 0,
11
- maxDelay: 3000,
12
- factor: 2,
13
- maxAttempts: 5,
14
- timeout: 0,
15
- jitter: true,
16
- minDelay: 0,
17
- handleError: errorAbortHandler,
18
- handleTimeout: null,
19
- beforeAttempt: null,
20
- calculateDelay: null,
21
- } as RetryOptions
@@ -1,28 +0,0 @@
1
- const discord = 'https://discord.gg/mvQunrx6NG'
2
- export class BaseError extends Error {
3
- timestamp: string
4
-
5
- constructor(
6
- public baseType: string,
7
- public type: string,
8
- public code: string,
9
- msg: string,
10
-
11
- public paramsUsed: any,
12
- fixSuggestion: string,
13
- docLink: string,
14
- isInternal = false,
15
- ) {
16
- super(`${msg}\n\n${fixSuggestion}\nDocs: ${docLink}\nDiscord: ${discord}`)
17
- if (isInternal) {
18
- this.loadEnd()
19
- }
20
- this.message += '\n\nTrace:'
21
- this.timestamp = new Date().toUTCString()
22
- }
23
-
24
- loadEnd() {
25
- this.message +=
26
- '\n\nThis is an internal sdk error. Please contact the fun team at our Discord for the fastest response.'
27
- }
28
- }
@@ -1,175 +0,0 @@
1
- import { BaseError } from './BaseError'
2
- import FWErrors from './errors.json'
3
- import { ErrorBaseType, ErrorCode, ErrorType } from './types'
4
- export class ClientError extends BaseError {
5
- constructor(
6
- type: string,
7
- code: string,
8
- msg: string,
9
- paramsUsed: any,
10
- fixSuggestion: string,
11
- docLink: string,
12
- ) {
13
- super(
14
- ErrorBaseType.ClientError,
15
- type,
16
- code,
17
- msg,
18
- paramsUsed,
19
- fixSuggestion,
20
- docLink,
21
- false,
22
- )
23
- }
24
- }
25
-
26
- export class InvalidParameterError extends ClientError {
27
- constructor(
28
- code: string,
29
- msg: string,
30
- paramsUsed: any,
31
- fixSuggestion: string,
32
- docLink: string,
33
- ) {
34
- super(
35
- ErrorType.InvalidParameter,
36
- code,
37
- msg,
38
- paramsUsed,
39
- fixSuggestion,
40
- docLink,
41
- )
42
- }
43
- }
44
-
45
- export class ResourceNotFoundError extends ClientError {
46
- constructor(
47
- code: string,
48
- msg: string,
49
- paramsUsed: any,
50
- fixSuggestion: string,
51
- docLink: string,
52
- ) {
53
- if (msg.includes('Chain name not found')) {
54
- const { reqId } = JSON.parse(msg)
55
- msg = ': Chain name not found or not supported.'
56
- fixSuggestion = 'Change your EnvOptions to the correct chain identifier.'
57
- super(
58
- ErrorType.ResourceNotFound,
59
- ErrorCode.ChainNotSupported,
60
- msg,
61
- { reqId },
62
- fixSuggestion,
63
- docLink,
64
- )
65
- } else {
66
- super(
67
- ErrorType.ResourceNotFound,
68
- code,
69
- msg,
70
- paramsUsed,
71
- fixSuggestion,
72
- docLink,
73
- )
74
- }
75
- }
76
- }
77
-
78
- export class InvalidActionError extends ClientError {
79
- constructor(
80
- code: string,
81
- msg: string,
82
- paramsUsed: any,
83
- fixSuggestion: string,
84
- docLink: string,
85
- ) {
86
- super(
87
- ErrorType.InvalidAction,
88
- code,
89
- msg,
90
- paramsUsed,
91
- fixSuggestion,
92
- docLink,
93
- )
94
- }
95
- }
96
-
97
- export class ThrottlingError extends ClientError {
98
- constructor(
99
- code: string,
100
- msg: string,
101
- paramsUsed: any,
102
- fixSuggestion: string,
103
- docLink: string,
104
- ) {
105
- super(
106
- ErrorType.ThrottlingError,
107
- code,
108
- msg,
109
- paramsUsed,
110
- fixSuggestion,
111
- docLink,
112
- )
113
- }
114
- }
115
-
116
- export class AccessDeniedError extends ClientError {
117
- constructor(
118
- code: string,
119
- msg: string,
120
- paramsUsed: any,
121
- fixSuggestion: string,
122
- docLink: string,
123
- ) {
124
- super(
125
- ErrorType.AccessDeniedError,
126
- code,
127
- msg,
128
- paramsUsed,
129
- fixSuggestion,
130
- docLink,
131
- )
132
- }
133
- }
134
-
135
- export class UserOpFailureError extends ClientError {
136
- constructor(
137
- code: string,
138
- msg: string,
139
- paramsUsed: any,
140
- fixSuggestion: string,
141
- docLink: string,
142
- ) {
143
- const FWCode = findFWContractError(msg)
144
- if (FWCode) {
145
- const { reqId } = JSON.parse(msg)
146
- msg = FWErrors[FWCode].info
147
- fixSuggestion = FWErrors[FWCode].suggestion
148
- super(
149
- ErrorType.UserOpFailureError,
150
- ErrorCode.FunWalletErrorCode,
151
- msg,
152
- { reqId },
153
- fixSuggestion,
154
- docLink,
155
- )
156
- } else {
157
- super(
158
- ErrorType.UserOpFailureError,
159
- code,
160
- msg,
161
- paramsUsed,
162
- fixSuggestion,
163
- docLink,
164
- )
165
- }
166
- }
167
- }
168
-
169
- const findFWContractError = (msg: string) => {
170
- let match = msg.match(/FW\d{3}/)
171
- if (!match) {
172
- match = msg.match(/AA\d./)
173
- }
174
- return match?.[0]
175
- }
@@ -1,43 +0,0 @@
1
- import { BaseError } from './BaseError'
2
- import { ErrorBaseType, ErrorType } from './types'
3
-
4
- export class ServerError extends BaseError {
5
- constructor(
6
- type: string,
7
- code: string,
8
- msg: string,
9
- paramsUsed: any,
10
- fixSuggestion: string,
11
- docLink: string,
12
- ) {
13
- super(
14
- ErrorBaseType.ServerError,
15
- type,
16
- code,
17
- msg,
18
- paramsUsed,
19
- fixSuggestion,
20
- docLink,
21
- true,
22
- )
23
- }
24
- }
25
-
26
- export class InternalFailureError extends ServerError {
27
- constructor(
28
- code: string,
29
- msg: string,
30
- paramsUsed: any,
31
- fixSuggestion: string,
32
- docLink: string,
33
- ) {
34
- super(
35
- ErrorType.InternalServerFailure,
36
- code,
37
- msg,
38
- paramsUsed,
39
- fixSuggestion,
40
- docLink,
41
- )
42
- }
43
- }