Skip to content

Commit

Permalink
chore(tsconfig): use existing tsconfig.json configurations from exist…
Browse files Browse the repository at this point in the history
…ing (history) package
  • Loading branch information
ajimae committed Jul 13, 2021
1 parent 70df158 commit bd87262
Show file tree
Hide file tree
Showing 31 changed files with 57 additions and 208 deletions.
33 changes: 0 additions & 33 deletions packages/history-sdk/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,3 @@
// module.exports = {
// preset: 'ts-jest',
// testEnvironment: 'node',
// collectCoverage: true,
// coverageDirectory: 'coverage',
// roots: ['<rootDir>/test'],
// testPathIgnorePatterns: [
// "/node_modules/"
// ],
// verbose: true,
// coverageThreshold: {
// global: {
// // statements: 90
// }
// },
// globals: {
// 'ts-jest': {
// diagnostics: false,
// ignoreCodes: ["TS7019", "TS2345", "TS7006", "TS7053"]
// }
// },
// reporters: [
// 'default',
// process.env.CI === 'true'
// ? [
// 'jest-junit',
// { outputName: 'results.xml', outputDirectory: 'test-results' },
// ]
// : null,
// ].filter(elem => elem !== null),
// }


module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
Expand Down
2 changes: 0 additions & 2 deletions packages/history-sdk/test/helpers/ctp-api-helper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { createClient, createAuthForClientCredentialsFlow, createHttpClient } from '../../../sdk-client/src/index'
// import { createAuthMiddlewareForClientCredentialsFlow } from '@commercetools/sdk-middleware-auth'
// import { createHttpMiddleware } from '@commercetools/sdk-middleware-http'
import {
ApiRoot,
createExecutorFromMiddlewares,
Expand Down
6 changes: 6 additions & 0 deletions packages/history-sdk/test/helpers/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ export async function sleep(millis: number) {
setTimeout(resolve, millis)
})
}

export const scopes = [
'view_audit_log:demo-1',
'manage_api_clients:demo-1',
'view_api_clients:demo-1'
]
2 changes: 1 addition & 1 deletion packages/history-sdk/test/misc.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ctpApiBuilder } from './helpers/ctp-api-helper'

test.skip('check can get project info', async () => {
test('check can get project info', async () => {
const res = await ctpApiBuilder
.get({ queryArgs: { limit: 1, offset: 0 } })
.execute()
Expand Down
4 changes: 0 additions & 4 deletions packages/importapi-sdk/test/helpers/ctp-api-helper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// import { createClient } from '@commercetools/sdk-client'
// import { createAuthMiddlewareForClientCredentialsFlow } from '@commercetools/sdk-middleware-auth'
// import { createHttpMiddleware } from '@commercetools/sdk-middleware-http'
import { createClient, createAuthForClientCredentialsFlow, createHttpClient } from '../../../sdk-client/src/index'
import fetch from 'node-fetch'
import { requireEnvVar } from './test-utils'
Expand All @@ -16,7 +13,6 @@ const clientSecret = requireEnvVar('CTP_CLIENT_SECRET')
const authURL = requireEnvVar('CTP_AUTH_URL')
const ctp_host = requireEnvVar('CTP_IMPORT_URL')

// TODO: fix this error
const authMiddleware = createAuthForClientCredentialsFlow({
host: authURL,
projectKey,
Expand Down
5 changes: 0 additions & 5 deletions packages/ml-sdk/test/helpers/api-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// import { createClient } from '@commercetools/sdk-client'
// import { createAuthMiddlewareForClientCredentialsFlow } from '@commercetools/sdk-middleware-auth'
// import { createHttpMiddleware } from '@commercetools/sdk-middleware-http'
import { createClient, createAuthForClientCredentialsFlow, createHttpClient } from '../../../sdk-client/src/index'
import fetch from 'node-fetch'
import {
Expand All @@ -19,13 +16,11 @@ const ml_host = requireEnvVar('CTP_ML_API_URL')
const authMiddleware = createAuthForClientCredentialsFlow({
host: authURL,
projectKey,
oauthUri: '',
credentials: {
clientId,
clientSecret,
},
fetch,
scopes: ['']
})

const httpMiddleware = createHttpClient({
Expand Down
4 changes: 0 additions & 4 deletions packages/ml-sdk/test/helpers/ctp-api-helper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// import { createClient } from '@commercetools/sdk-client'
// import { createAuthMiddlewareForClientCredentialsFlow } from '@commercetools/sdk-middleware-auth'
// import { createHttpMiddleware } from '@commercetools/sdk-middleware-http'
import { createClient, createAuthForClientCredentialsFlow, createHttpClient } from '../../../sdk-client/src/index'
import {
ApiRoot,
Expand All @@ -16,7 +13,6 @@ const clientSecret = requireEnvVar('CTP_CLIENT_SECRET')
const authURL = requireEnvVar('CTP_AUTH_URL')
const ctp_host = requireEnvVar('CTP_API_URL')

// TODO: Fix this error
const authMiddleware = createAuthForClientCredentialsFlow({
host: authURL,
projectKey,
Expand Down
2 changes: 1 addition & 1 deletion packages/ml-sdk/test/helpers/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export function requireEnvVar(varName: string): string {

export async function sleep(millis: number) {
return new Promise((resolve, error) => {
setTimeout(() => resolve(), millis)
setTimeout(resolve, millis)
})
}
4 changes: 0 additions & 4 deletions packages/platform-sdk/test/helpers/ctp-api-helper.old.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// import { createClient } from '@commercetools/sdk-client'
// import { createAuthMiddlewareForClientCredentialsFlow } from '@commercetools/sdk-middleware-auth'
// import { createHttpMiddleware } from '@commercetools/sdk-middleware-http'

import { createAuthForClientCredentialsFlow, createHttpClient, createClient } from '../../../sdk-client/src/index'

import fetch from 'node-fetch'
Expand Down
1 change: 0 additions & 1 deletion packages/platform-sdk/test/helpers/ctp-api-helper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// import { createClient } from '@commercetools/sdk-client'
import { createClient } from '../../../sdk-client/src/index'
import { createAuthMiddlewareForClientCredentialsFlow } from '@commercetools/sdk-middleware-auth'
import { createHttpMiddleware } from '@commercetools/sdk-middleware-http'
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-client/src/builder/ApiRootBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiRoot, createApiBuilderFromCtpClient } from '@commercetools/platform-sdk'
import { Middleware, AuthMiddlewareOptions, HttpMiddlewareOptions } from '../types/sdk'
import { Middleware, AuthMiddlewareOptions, HttpMiddlewareOptions } from '../types/sdk.d'
import { default as createClient } from '../sdk-client/client'
import { default as createHttpClient } from '../sdk-middleware-http/http'
import { default as createAuthForClientCredentialsFlow } from '../sdk-middleware-auth/client-credentials-flow'
Expand Down
4 changes: 0 additions & 4 deletions packages/sdk-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,5 @@ export { default as createAuthWithExistingToken } from './sdk-middleware-auth/ex
// http
export { default as createHttpClient } from './sdk-middleware-http/http'

// platfrom sdk
// @ts-ignore
// export { createApiBuilderFromCtpClient } from '../../platform-sdk/src/index' // import directly from project structure.
// export { createApiBuilderFromCtpClient } from '@commercetools/typescript-sdk'
export { createApiBuilderFromCtpClient } from '@commercetools/platform-sdk'
export { default as ApiRootBuilder } from './builder/ApiRootBuilder';
13 changes: 9 additions & 4 deletions packages/sdk-client/src/sdk-client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ProcessOptions,
SuccessResult,
ClientResponse,
} from '../types/sdk'
} from '../types/sdk.d'
import validate from './validate'

function compose(...funcs: Array<Function>): Function {
Expand Down Expand Up @@ -97,8 +97,13 @@ export default function createClient(options: ClientOptions): Client {
}

return new Promise((resolve: Function, reject: Function) => {
const [path, queryString] = request.uri.split('?')
const requestQuery = { ...qs.parse(queryString) }
let _path, _queryString = '';
if (request && request.uri) {
const [path, queryString] = request.uri.split('?')
_path = path;
_queryString = queryString;
}
const requestQuery = { ...qs.parse(_queryString) }
const query = {
// defaults
limit: 20,
Expand All @@ -121,7 +126,7 @@ export default function createClient(options: ClientOptions): Client {
const enhancedQueryString = qs.stringify(enhancedQuery)
const enhancedRequest = {
...request,
uri: `${path}?${enhancedQueryString}&${originalQueryString}`,
uri: `${_path}?${enhancedQueryString}&${originalQueryString}`,
}

try {
Expand Down
5 changes: 2 additions & 3 deletions packages/sdk-client/src/sdk-client/errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @ts-nocheck
import { JsonObject } from "../types/sdk"
import { JsonObject } from "../types/sdk.d"

function defineError(this: any, statusCode: number, message: string, meta: JsonObject<any> = {}) {
this.status = this.statusCode = this.code = statusCode
Expand All @@ -16,7 +15,7 @@ function defineError(this: any, statusCode: number, message: string, meta: JsonO
export function NetworkError(this: any, ...args: Array<unknown>) {
defineError.call(this, 0 /* special code to indicate network errors */, ...args);
}
export function HttpError(...args: { [key: string]: any }[]) {
export function HttpError(...args: Array<unknown>) {
defineError.call(this, /* code will be passed as arg */ ...args);
}
export function BadRequest(this: any, ...args: Array<unknown>) {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-client/src/sdk-client/validate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import METHODS from './allowed-methods'
import { ClientRequest } from '../types/sdk'
import { ClientRequest } from '../types/sdk.d'

/**
* @throws {Error}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
MiddlewareResponse,
Next,
Task,
} from '../types/sdk'
} from '../types/sdk.d'

import { buildRequestForAnonymousSessionFlow } from './build-requests'
import authMiddlewareBase from './base-auth-flow'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
PasswordAuthMiddlewareOptions,
AuthMiddlewareOptions,
executeRequestOptions,
} from '../types/sdk'
} from '../types/sdk.d'
import { buildRequestForRefreshTokenFlow } from './build-requests'

function mergeAuthHeader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
AuthMiddlewareOptions,
PasswordAuthMiddlewareOptions,
RefreshAuthMiddlewareOptions,
} from '../types/sdk'
} from '../types/sdk.d'

interface IBuiltRequestParams {
basicAuth: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AuthMiddlewareOptions, TokenCacheOptions } from '../types/sdk'
import { AuthMiddlewareOptions, TokenCacheOptions } from '../types/sdk.d'

export default function buildTokenCacheKey(
options: AuthMiddlewareOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
MiddlewareResponse,
Next,
Task,
} from '../types/sdk'
} from '../types/sdk.d'

import { buildRequestForClientCredentialsFlow } from './build-requests'
import buildTokenCacheKey from './build-token-cache-key'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
MiddlewareResponse,
ExistingTokenMiddlewareOptions,
Next,
} from '../types/sdk'
} from '../types/sdk.d'

export default function createAuthMiddlewareWithExistingToken(
authorization: string = '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
MiddlewareResponse,
Next,
Task,
} from '../types/sdk'
} from '../types/sdk.d'

import { buildRequestForPasswordFlow } from './build-requests'
import authMiddlewareBase from './base-auth-flow'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
MiddlewareResponse,
Next,
Task,
} from '../types/sdk'
} from '../types/sdk.d'

import { buildRequestForRefreshTokenFlow } from './build-requests'
import authMiddlewareBase from './base-auth-flow'
Expand Down
18 changes: 5 additions & 13 deletions packages/sdk-client/src/sdk-middleware-http/http.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-nocheck
import {
JsonObject,
HttpErrorType,
Expand All @@ -7,9 +6,9 @@ import {
MiddlewareRequest,
MiddlewareResponse,
Next,
MethodType,
ClientRequest,
} from '../types/sdk'
RequestOptions,
} from '../types/sdk.d'

import getErrorByCode, { NetworkError, HttpError } from '../sdk-client/errors'
import parseHeaders from './parse-headers'
Expand Down Expand Up @@ -112,26 +111,19 @@ export default function createHttpMiddleware({
: // NOTE: `stringify` of `null` gives the String('null')
JSON.stringify(request.body || undefined)

const requestHeader: JsonObject<string> = { ...request.headers }
const requestHeader = { ...request.headers }
if (!Object.prototype.hasOwnProperty.call(requestHeader, 'Content-Type')) {
requestHeader['Content-Type'] = 'application/json'
}
if (body) {
requestHeader['Content-Length'] = Buffer.byteLength(body).toString()
}
type RequestOptions = {
method?: MethodType
headers?: JsonObject<string>
credentials?: any
signal?: any
body?: any
}
const fetchOptions: RequestOptions = {
method: request.method,
headers: requestHeader,
}
if (credentialsMode) {
fetchOptions.credentials = credentialsMode
fetchOptions.credentialsMode = credentialsMode
}
if (abortController) {
fetchOptions.signal = abortController.signal
Expand Down Expand Up @@ -183,7 +175,7 @@ export default function createHttpMiddleware({
parsed = result
}

const parsedResponse: MiddlewareResponse = {
const parsedResponse: any = {
...response,
body: parsed,
statusCode: res.status,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JsonObject } from "../types/sdk"
import { JsonObject } from "../types/sdk.d"

export default function parseHeaders(headers: JsonObject<any>): JsonObject<string> {
if (headers.raw)
Expand Down
Loading

0 comments on commit bd87262

Please sign in to comment.