Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Fixing linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
paulomarg committed Dec 19, 2023
1 parent d6256c0 commit 7299885
Show file tree
Hide file tree
Showing 38 changed files with 74 additions and 112 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {
es2021: true,
},
extends: ["plugin:@shopify/typescript", "plugin:@shopify/prettier"],
ignorePatterns: ["dist/"],
ignorePatterns: ["dist/", "node_modules/"],
rules: {
"no-console": 0,
"@typescript-eslint/naming-convention": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type UnpackedInputMaybe<InputType> = InputType extends InputMaybe<infer R>
export type OperationVariables<
Operation extends keyof Operations,
Operations extends AllOperations,
> = Operations[Operation]["variables"] extends { [key: string]: never }
? { [key: string]: never }
> = Operations[Operation]["variables"] extends Record<string, never>
? Record<string, never>
: {
variables?: {
[k in keyof Operations[Operation]["variables"]]: UnpackedInputMaybe<
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-client/src/api-client-utilities/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export type ApiClientRequestOptions<
retries?: number;
} & (Operation extends keyof Operations
? OperationVariables<Operation, Operations>
: { variables?: { [key: string]: any } });
: { variables?: Record<string, any> });

export type ApiClientRequestParams<
Operation extends keyof Operations,
Expand Down
12 changes: 3 additions & 9 deletions packages/graphql-client/src/graphql-client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ export type CustomFetchApi = (
},
) => Promise<Response>;

interface OperationVariables {
[key: string]: any;
}
type OperationVariables = Record<string, any>;

export interface Headers {
[key: string]: string;
}
export type Headers = Record<string, string>;

export interface ResponseErrors {
networkStatusCode?: number;
Expand All @@ -22,9 +18,7 @@ export interface ResponseErrors {
response?: Response;
}

export interface GQLExtensions {
[key: string]: any;
}
export type GQLExtensions = Record<string, any>;

export interface FetchResponseBody<TData = any> {
data?: Partial<TData>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface Test {
const port: number = parseInt(process.env.HTTP_SERVER_PORT || '3000', 10);
const errorStatusText = 'Did not work';
const requestId = 'Request id header';
const tests: {[key: string | number]: Test} = {
const tests: Record<string | number, Test> = {
200: {
expectedRequest: initTestRequest(),
testResponse: initTestResponse(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ function handle(_signal: any): void {

function setRestClientRetryTime(time: number) {
// We de-type HttpClient here so we can alter its readonly time property
(HttpClient as unknown as {[key: string]: number}).RETRY_WAIT_TIME = time;
(HttpClient as any).RETRY_WAIT_TIME = time;
}

process.on('SIGINT', handle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function params(

function setRestClientRetryTime(time: number) {
// We de-type HttpClient here so we can alter its readonly time property
(HttpClient as unknown as {[key: string]: number}).RETRY_WAIT_TIME = time;
(HttpClient as any).RETRY_WAIT_TIME = time;
}

/* eslint-disable-next-line import/no-anonymous-default-export */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const handleGraphqlTest = async ({
const graphqlClient = graphqlClientFactory(apiServer);

let operation: string;
let variables: {[key: string]: any} | undefined;
let variables: Record<string, any> | undefined;
try {
const bodyJSON = JSON.parse(testRequest.body!);
operation = bodyJSON.query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ interface ExpectRequestParams {
domain: string;
path: string;
query?: string;
headers?: {[key: string]: any};
data?: string | {[key: string]: any} | null;
headers?: Record<string, any>;
data?: string | Record<string, any> | null;
attempts?: number;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/shopify-api/lib/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ export type ShopifyAuth<Future extends FutureFlagOptions> = {
buildEmbeddedAppUrl: BuildEmbeddedAppUrl;
} & (FeatureEnabled<Future, 'unstable_tokenExchange'> extends true
? {tokenExchange: TokenExchange}
: {[key: string]: never});
: Record<string, never>);
4 changes: 1 addition & 3 deletions packages/shopify-api/lib/auth/oauth/__tests__/oauth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import {shopifyApi} from '../../..';
const VALID_NONCE = 'noncenoncenonce';
jest.mock('../nonce', () => ({nonce: jest.fn(() => VALID_NONCE)}));

interface QueryMock {
[key: string]: any;
}
type QueryMock = Record<string, any>;

let shop: string;

Expand Down
4 changes: 2 additions & 2 deletions packages/shopify-api/lib/auth/oauth/safe-compare.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as ShopifyErrors from '../../error';

export type SafeCompare = (
strA: string | {[key: string]: string} | string[] | number[],
strB: string | {[key: string]: string} | string[] | number[],
strA: string | Record<string, string> | string[] | number[],
strB: string | Record<string, string> | string[] | number[],
) => boolean;

export const safeCompare: SafeCompare = (strA, strB) => {
Expand Down
6 changes: 2 additions & 4 deletions packages/shopify-api/lib/billing/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,9 @@ export type BillingConfigItem<
? BillingConfigOneTimePlan | BillingConfigSubscriptionLineItemPlan
: BillingConfigLegacyItem;

export interface BillingConfig<
export type BillingConfig<
Future extends FutureFlagOptions = FutureFlagOptions,
> {
[plan: string]: BillingConfigItem<Future>;
}
> = Record<string, BillingConfigItem<Future>>;

export type RequestConfigOverrides =
| Partial<BillingConfigOneTimePlan>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('GraphQL client', () => {
const shopify = shopifyApi(testConfig());

const client = new shopify.clients.Graphql({session});
const customHeader: {[key: string]: string} = {
const customHeader: Record<string, string> = {
'X-Glib-Glob': 'goobers',
};

Expand Down Expand Up @@ -111,7 +111,7 @@ describe('GraphQL client', () => {
buildExpectedResponse(successResponse),
);

const customHeaders: {[key: string]: string} = {};
const customHeaders: Record<string, string> = {};
customHeaders[ShopifyHeader.AccessToken] =
shopify.config.adminApiAccessToken;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ describe('REST client', () => {

const client = new shopify.clients.Rest({session});

const customHeaders: {[key: string]: string} = {
const customHeaders: Record<string, string> = {
'X-Not-A-Real-Header': 'some_value',
};

Expand Down Expand Up @@ -385,7 +385,7 @@ describe('REST client', () => {
buildExpectedResponse(successResponse),
);

const customHeaders: {[key: string]: string} = {};
const customHeaders: Record<string, string> = {};
customHeaders[ShopifyHeader.AccessToken] =
shopify.config.adminApiAccessToken;

Expand Down
7 changes: 3 additions & 4 deletions packages/shopify-api/lib/clients/admin/graphql/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class GraphqlClient {
>
> {
let operation: Operation;
let variables: {[key: string]: any} | undefined;
let variables: Record<string, any> | undefined;
let headers: HeaderParams = {};
let tries: number | undefined;
if (typeof params === 'object') {
Expand Down Expand Up @@ -142,16 +142,15 @@ export class GraphqlClient {
: T;

// Get errors array
const errors = (body as unknown as {[key: string]: unknown})
.errors as any[];
const errors = (body as unknown as Record<string, unknown>).errors as any[];

const responseHeaders = Object.fromEntries(response.headers.entries());

// Throw error if response contains errors
if (errors?.length > 0) {
throw new ShopifyErrors.GraphqlQueryError({
message: errors[0]?.message ?? 'GraphQL query returned errors',
response: body as unknown as {[key: string]: unknown},
response: body as unknown as Record<string, unknown>,
headers: responseHeaders,
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/shopify-api/lib/clients/admin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {RequestReturn, QueryParams} from '../http_client/types';

export interface PageInfoParams {
path: string;
query: {[key: string]: QueryParams};
query: Record<string, QueryParams>;
}

export interface PageInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function graphqlProxy(config: ConfigInterface): GraphqlProxy {
const client = new GraphqlClient({session});

let query: string;
let variables: {[key: string]: any} | undefined;
let variables: Record<string, any> | undefined;
if (typeof rawBody === 'string') {
query = rawBody;
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/shopify-api/lib/clients/graphql_proxy/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {RequestReturn} from '../http_client/types';

export interface GraphqlProxyParams {
session: Session;
rawBody: string | {[key: string]: any};
rawBody: string | Record<string, any>;
}

export type GraphqlProxy = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1021,5 +1021,5 @@ describe('HTTP client', () => {

function setRestClientRetryTime(time: number) {
// We de-type HttpClient here so we can alter its readonly time property
(HttpClient as unknown as {[key: string]: number}).RETRY_WAIT_TIME = time;
(HttpClient as any).RETRY_WAIT_TIME = time;
}
6 changes: 3 additions & 3 deletions packages/shopify-api/lib/clients/http_client/http_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class HttpClient {
static readonly RETRY_WAIT_TIME = 1000;
// 5 minutes
static readonly DEPRECATION_ALERT_DELAY = 300000;
loggedDeprecations: {[key: string]: number} = {};
loggedDeprecations: Record<string, number> = {};
readonly domain: string;

public constructor(params: HttpClientParams) {
Expand Down Expand Up @@ -126,7 +126,7 @@ export class HttpClient {
typeof data === 'string'
? data
: new URLSearchParams(
data as {[key: string]: string},
data as Record<string, string>,
).toString();
break;
case DataType.GraphQL:
Expand Down Expand Up @@ -232,7 +232,7 @@ export class HttpClient {
);
}

let body: {[key: string]: string} | string | T = {};
let body: Record<string, string> | string | T = {};

if (response.body) {
try {
Expand Down
10 changes: 4 additions & 6 deletions packages/shopify-api/lib/clients/http_client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import {Method} from '@shopify/network';

import {Headers} from '../../../runtime/http';

export interface HeaderParams {
[key: string]: string | number | string[];
}
export type HeaderParams = Record<string, string | number | string[]>;

/* eslint-disable @shopify/typescript/prefer-pascal-case-enums */
export enum DataType {
Expand All @@ -24,14 +22,14 @@ export type QueryParams =
export interface GetRequestParams {
path: string;
type?: DataType;
data?: {[key: string]: unknown} | string;
query?: {[key: string]: QueryParams};
data?: Record<string, unknown> | string;
query?: Record<string, QueryParams>;
extraHeaders?: HeaderParams;
tries?: number;
}

export type PostRequestParams = GetRequestParams & {
data: {[key: string]: unknown} | string;
data: Record<string, unknown> | string;
};

export type PutRequestParams = PostRequestParams;
Expand Down
7 changes: 3 additions & 4 deletions packages/shopify-api/lib/clients/storefront/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class StorefrontClient {
const config = this.storefrontClass().config;

let operation: Operation;
let variables: {[key: string]: any} | undefined;
let variables: Record<string, any> | undefined;
let headers: HeaderParams = {};
let tries: number | undefined;
if (typeof params === 'object') {
Expand Down Expand Up @@ -160,16 +160,15 @@ export class StorefrontClient {
: T;

// Get errors array
const errors = (body as unknown as {[key: string]: unknown})
.errors as any[];
const errors = (body as unknown as Record<string, unknown>).errors as any[];

const responseHeaders = Object.fromEntries(response.headers.entries());

// Throw error if response contains errors
if (errors?.length > 0) {
throw new ShopifyErrors.GraphqlQueryError({
message: errors[0]?.message ?? 'GraphQL query returned errors',
response: body as unknown as {[key: string]: unknown},
response: body as unknown as Record<string, unknown>,
headers: responseHeaders,
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/shopify-api/lib/clients/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface GraphqlQueryOptions<
Operations extends AllOperations,
> {
variables?: ApiClientRequestOptions<Operation, Operations>['variables'];
extraHeaders?: {[key: string]: string | number};
extraHeaders?: Record<string, string | number>;
tries?: number;
}

Expand Down
12 changes: 6 additions & 6 deletions packages/shopify-api/lib/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export class HttpMaxRetriesError extends ShopifyError {}
interface HttpResponseData {
code: number;
statusText: string;
body?: {[key: string]: unknown};
headers?: {[key: string]: unknown};
body?: Record<string, unknown>;
headers?: Record<string, unknown>;
}
interface HttpResponseErrorParams extends HttpResponseData {
message: string;
Expand Down Expand Up @@ -70,17 +70,17 @@ export class HttpThrottlingError extends HttpRetriableError<HttpThrottlingErrorD

export class RestResourceError extends ShopifyError {}
export class GraphqlQueryError extends ShopifyError {
readonly response: {[key: string]: unknown};
headers?: {[key: string]: unknown};
readonly response: Record<string, unknown>;
headers?: Record<string, unknown>;

public constructor({
message,
response,
headers,
}: {
message: string;
response: {[key: string]: unknown};
headers?: {[key: string]: unknown};
response: Record<string, unknown>;
headers?: Record<string, unknown>;
}) {
super(message);
this.response = response;
Expand Down
2 changes: 1 addition & 1 deletion packages/shopify-api/lib/logger/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {LogContext} from './types';
export type LoggerFunction = (
severity: LogSeverity,
message: string,
context?: {[key: string]: any},
context?: Record<string, any>,
) => void;

export function log(config: ConfigInterface): LoggerFunction {
Expand Down
4 changes: 1 addition & 3 deletions packages/shopify-api/lib/logger/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export interface LogContext {
[key: string]: any;
}
export type LogContext = Record<string, any>;
4 changes: 2 additions & 2 deletions packages/shopify-api/lib/utils/processed-query.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default class ProcessedQuery {
static stringify(keyValuePairs?: {[key: string]: any}): string {
static stringify(keyValuePairs?: Record<string, any>): string {
if (!keyValuePairs || Object.keys(keyValuePairs).length === 0) return '';

return new ProcessedQuery().putAll(keyValuePairs).stringify();
Expand All @@ -11,7 +11,7 @@ export default class ProcessedQuery {
this.processedQuery = new URLSearchParams();
}

putAll(keyValuePairs: {[key: string]: any}): ProcessedQuery {
putAll(keyValuePairs: Record<string, any>): ProcessedQuery {
Object.entries(keyValuePairs).forEach(([key, value]: [string, any]) =>
this.put(key, value),
);
Expand Down
Loading

0 comments on commit 7299885

Please sign in to comment.