Skip to content

Commit 1f1e1b8

Browse files
committed
Updates to get linting working
1 parent 89129e5 commit 1f1e1b8

File tree

6 files changed

+29
-17
lines changed

6 files changed

+29
-17
lines changed

.eslintrc

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
"no-cond-assign": 0,
1515
"class-methods-use-this": 0,
1616
"no-underscore-dangle": 0,
17-
"no-useless-constructor": 0
17+
"no-useless-constructor": 0,
18+
// Note: you must disable the base rule as it can report incorrect errors
19+
"no-shadow": 0,
20+
"@typescript-eslint/no-shadow": "warn",
21+
"no-empty-function": 0
1822
},
1923
"settings": {
2024
"import/resolver": {

src/core/sdk-exceptions.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { ErrorCode } from '../types';
55
export class MagicAdminSDKError extends Error {
66
__proto__ = Error;
77

8-
constructor(public code: ErrorCode, message: string, public data: any[] = []) {
8+
constructor(
9+
public code: ErrorCode,
10+
message: string,
11+
public data: any[] = [],
12+
) {
913
super(`Magic Admin SDK Error: [${code}] ${message}`);
1014
Object.setPrototypeOf(this, MagicAdminSDKError.prototype);
1115
}

src/core/sdk.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { createApiKeyMissingError } from './sdk-exceptions';
12
import { TokenModule } from '../modules/token';
23
import { UsersModule } from '../modules/users';
34
import { UtilsModule } from '../modules/utils';
45
import { MagicAdminSDKAdditionalConfiguration } from '../types';
56
import { get } from '../utils/rest';
6-
import { createApiKeyMissingError } from './sdk-exceptions';
77

88
export class MagicAdminSDK {
99
public readonly apiBaseUrl: string;
@@ -35,7 +35,10 @@ export class MagicAdminSDK {
3535
* @param secretApiKey
3636
* @param options
3737
*/
38-
constructor(public readonly secretApiKey?: string, options?: MagicAdminSDKAdditionalConfiguration) {
38+
constructor(
39+
public readonly secretApiKey?: string,
40+
options?: MagicAdminSDKAdditionalConfiguration,
41+
) {
3942
const endpoint = options?.endpoint ?? 'https://api.magic.link';
4043
this.apiBaseUrl = endpoint.replace(/\/+$/, '');
4144
this.clientId = options?.clientId ?? null;

src/types/utils-types.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export interface ValidateTokenOwnershipResponse {
2-
valid: boolean;
3-
error_code: string;
4-
message: string;
2+
valid: boolean;
3+
error_code: string;
4+
message: string;
55
}

src/utils/parse-didt.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Claim, ParsedDIDToken } from '../types';
1+
import { decodeValue } from './codec';
22
import { isDIDTClaim } from './type-guards';
33
import { createMalformedTokenError } from '../core/sdk-exceptions';
4-
import { decodeValue } from './codec';
4+
import { Claim, ParsedDIDToken } from '../types';
55

66
interface ParseDIDTokenResult {
77
raw: [string, string];

src/utils/rest.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { RequestInit } from 'node-fetch';
2-
import { createServiceError } from '../core/sdk-exceptions';
2+
33
import { fetch } from './fetch';
4+
import { createServiceError } from '../core/sdk-exceptions';
45

5-
interface MagicAPIResponse<TData = {}> {
6+
interface MagicAPIResponse<TData> {
67
data?: TData;
78
error_code?: string;
89
message?: string;
@@ -12,10 +13,10 @@ interface MagicAPIResponse<TData = {}> {
1213
/**
1314
* Performs a `fetch` to the given URL with the configured `init` object.
1415
*/
15-
async function emitRequest<TResponse extends any = {}>(url: string, init?: RequestInit): Promise<Partial<TResponse>> {
16+
async function emitRequest<TResponse>(url: string, init?: RequestInit): Promise<Partial<TResponse>> {
1617
const json: MagicAPIResponse<TResponse> = await fetch(url, init)
17-
.then(res => res.json())
18-
.catch(err => {
18+
.then((res) => res.json())
19+
.catch((err) => {
1920
throw createServiceError(err);
2021
});
2122

@@ -29,7 +30,7 @@ async function emitRequest<TResponse extends any = {}>(url: string, init?: Reque
2930
/**
3031
* Generates an encoded URL with query string from a dictionary of values.
3132
*/
32-
function generateQuery<T extends Record<string, string | number | boolean> = {}>(url: string, params?: T) {
33+
function generateQuery<T extends Record<string, string | number | boolean>>(url: string, params?: T) {
3334
let query = '?';
3435
if (params) {
3536
for (const [key, value] of Object.entries(params)) query += `${key}=${value}&`;
@@ -41,7 +42,7 @@ function generateQuery<T extends Record<string, string | number | boolean> = {}>
4142
/**
4243
* POSTs to Magic's API.
4344
*/
44-
export function post<TBody extends Record<string, string | number | boolean> = {}, TResponse extends any = {}>(
45+
export function post<TBody extends Record<string, string | number | boolean>, TResponse>(
4546
url: string,
4647
secretApiKey: string,
4748
body: TBody,
@@ -56,7 +57,7 @@ export function post<TBody extends Record<string, string | number | boolean> = {
5657
/**
5758
* GETs from Magic's API.
5859
*/
59-
export function get<TResponse extends any = {}>(url: string, secretApiKey: string, params?: any) {
60+
export function get<TResponse>(url: string, secretApiKey: string, params?: any) {
6061
const urlWithParams = generateQuery(url, params);
6162
return emitRequest<TResponse>(urlWithParams, {
6263
method: 'GET',

0 commit comments

Comments
 (0)