Skip to content

Commit

Permalink
Fix self-referencing package problems
Browse files Browse the repository at this point in the history
  • Loading branch information
pozylon committed Nov 22, 2024
1 parent 5f857ae commit 19ae1dc
Show file tree
Hide file tree
Showing 291 changed files with 388 additions and 394 deletions.
4 changes: 2 additions & 2 deletions docs/docs/advanced/write-plugins/filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Below is a simple filter plugin that will filter products based on there attribu
```typescript

import { IFilterAdapter, FilterAdapterActions, FilterContext } from '@unchainedshop/core-filters';
import { Context } from '@unchainedshop/api';
import { Context } from '../../../context.js';

const ShopAttributeFilter: IFilterAdapter = {
key: 'ch.shop.filter',
Expand Down Expand Up @@ -157,7 +157,7 @@ Below is a simplified implementation of the `ShopAttributeFilter` above, this ti

```typescript
import { IFilterAdapter, FilterAdapterActions, FilterContext } from '@unchainedshop/core-filters';
import { Context } from '@unchainedshop/api';
import { Context } from '../../../context.js';

const ShopAttributeFilter: IFilterAdapter = {
...FilterAdapter,
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/advanced/write-plugins/warehousing.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
WarehousingContext,
WarehousingProviderType,
} from '@unchainedshop/core-warehousing';
import { Context } from '@unchainedshop/api';
import { Context } from '../../../context.js';

const Store: IWarehousingAdapter = {
key: 'shop.unchained.warehousing.store',
Expand Down
5 changes: 3 additions & 2 deletions packages/api/src/api-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import {
createContextResolver,
setCurrentContextResolver,
getCurrentContextResolver,
AdminUiConfig,
} from './context.js';
import { UnchainedCore } from '@unchainedshop/core';
import { AdminUiConfig } from './types.js';

export * from './context.js';
export * from './types.js';
export * from './locale-context.js';
export * from './loaders/index.js';
export * as acl from './acl.js';
export * as errors from './errors.js';
export * as roles from './roles/index.js';
Expand Down
39 changes: 36 additions & 3 deletions packages/api/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
import fs from 'fs';
import path from 'path';
import { UnchainedCore } from '@unchainedshop/core';
import instantiateLoaders from './loaders/index.js';
import { getLocaleContext } from './locale-context.js';
import instantiateLoaders, { UnchainedLoaders } from './loaders/index.js';
import { getLocaleContext, UnchainedLocaleContext } from './locale-context.js';
import { UnchainedServerOptions } from './api-index.js';
import { Context, UnchainedHTTPServerContext } from './types.js';
import { User } from '@unchainedshop/core-users';

export interface UnchainedUserContext {
login: (user: User) => Promise<{ _id: string; tokenExpires: Date }>;
logout: () => Promise<boolean>;
userId?: string;
user?: User;
remoteAddress?: string;
remotePort?: string;
userAgent?: string;
}

export interface CustomAdminUiProperties {
entityName: string;
inlineFragment: string;
}

export interface AdminUiConfig {
customProperties?: CustomAdminUiProperties[];
}

export type UnchainedHTTPServerContext = {
setHeader: (key: string, value: string) => void;
getHeader: (key: string) => string | string[];
};

export type Context = UnchainedCore & {
version?: string;
roles?: any;
adminUiConfig?: AdminUiConfig;
} & UnchainedUserContext &
UnchainedLocaleContext &
UnchainedLoaders &
UnchainedHTTPServerContext;

let context;

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/express/createBulkImportMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createLogger } from '@unchainedshop/logger';
import { checkAction } from '../acl.js';
import { actions } from '../roles/index.js';
import { IncomingMessage } from 'http';
import { Context } from '../types.js';
import { Context } from '../context.js';

const logger = createLogger('unchained:bulk-import');

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/express/createERCMetadataMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IncomingMessage } from 'http';
import path from 'path';
import { createLogger } from '@unchainedshop/logger';
import { systemLocale } from '@unchainedshop/utils';
import { Context } from '../types.js';
import { Context } from '../context.js';

const logger = createLogger('unchained:erc-metadata');

Expand Down
53 changes: 52 additions & 1 deletion packages/api/src/loaders/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,58 @@
import DataLoader from 'dataloader';
import { systemLocale } from '@unchainedshop/utils';
import { UnchainedCore } from '@unchainedshop/core';
import { UnchainedLoaders } from '../types.js';
import { Product, ProductText, ProductMediaText, ProductMedia } from '@unchainedshop/core-products';
import { Filter, FilterText } from '@unchainedshop/core-filters';
import {
Assortment,
AssortmentLink,
AssortmentProduct,
AssortmentText,
AssortmentMediaType,
AssortmentMediaText,
} from '@unchainedshop/core-assortments';
import { File } from '@unchainedshop/core-files';
export interface UnchainedLoaders {
loaders: {
productLoader: InstanceType<typeof DataLoader<{ productId: string }, Product>>;
productLoaderBySKU: InstanceType<typeof DataLoader<{ sku: string }, Product>>;
productTextLoader: InstanceType<
typeof DataLoader<{ productId: string; locale: string }, ProductText>
>;
productMediaTextLoader: InstanceType<
typeof DataLoader<{ productMediaId: string; locale: string }, ProductMediaText>
>;

fileLoader: InstanceType<typeof DataLoader<{ fileId: string }, File>>;

filterLoader: InstanceType<typeof DataLoader<{ filterId: string }, Filter>>;
filterTextLoader: InstanceType<
typeof DataLoader<{ filterId: string; filterOptionValue?: string; locale: string }, FilterText>
>;

assortmentLoader: InstanceType<typeof DataLoader<{ assortmentId: string }, Assortment>>;
assortmentTextLoader: InstanceType<
typeof DataLoader<{ assortmentId: string; locale: string }, AssortmentText>
>;
assortmentLinkLoader: InstanceType<
typeof DataLoader<{ parentAssortmentId: string; childAssortmentId: string }, AssortmentLink>
>;
assortmentLinksLoader: InstanceType<
typeof DataLoader<{ parentAssortmentId?: string; assortmentId?: string }, AssortmentLink[]>
>;
assortmentProductLoader: InstanceType<
typeof DataLoader<{ assortmentId: string; productId: string }, AssortmentProduct>
>;
assortmentMediaTextLoader: InstanceType<
typeof DataLoader<{ assortmentMediaId: string; locale: string }, AssortmentMediaText>
>;

productMediasLoader: InstanceType<typeof DataLoader<{ productId?: string }, ProductMedia[]>>;
assortmentMediasLoader: InstanceType<
typeof DataLoader<{ assortmentId?: string }, AssortmentMediaType[]>
>;
};
}

function getLocaleStrings(localeObj: Intl.Locale) {
return [localeObj.baseName, localeObj.language, systemLocale.baseName, systemLocale.language];
Expand Down
10 changes: 9 additions & 1 deletion packages/api/src/locale-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ import {
} from '@unchainedshop/utils';
import { UnchainedCore } from '@unchainedshop/core';
import memoizee from 'memoizee';
import { UnchainedHTTPServerContext, UnchainedLocaleContext } from './types.js';
import { UnchainedHTTPServerContext } from './context.js';

export interface UnchainedLocaleContext {
countryContext: string;
localeContext: Intl.Locale;
currencyContext: string;
remoteAddress?: string;
remotePort?: string;
userAgent?: string;
}
const { NODE_ENV } = process.env;

export type GetHeaderFn = (key: string) => string | string[];
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/resolvers/mutations/accounts/addEmail.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { log } from '@unchainedshop/logger';
import { EmailAlreadyExistsError, UserNotFoundError } from '../../../errors.js';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

export default async function addEmail(
root: never,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { log } from '@unchainedshop/logger';
import { UserWeb3InvalidAddressError } from '../../../errors.js';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

export default async function addWeb3Address(
root: never,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { log } from '@unchainedshop/logger';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

export default async function addWebAuthnCredentials(
root: never,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { log } from '@unchainedshop/logger';
import { InvalidCredentialsError, PasswordInvalidError } from '../../../errors.js';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

export default async function changePassword(
root: never,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { UserData } from '@unchainedshop/core-users';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';
import { log } from '@unchainedshop/logger';
import {
AuthOperationFailedError,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { log } from '@unchainedshop/logger';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

export default async function createWebAuthnCredentialCreationOptions(
root: never,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { log } from '@unchainedshop/logger';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

export default async function createWebAuthnCredentialRequestOptions(
root: never,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { log } from '@unchainedshop/logger';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

import { UserData } from '@unchainedshop/core-users';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { log } from '@unchainedshop/logger';
import { UserNotFoundError } from '../../../errors.js';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

export default async function forgotPassword(
root: never,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { log } from '@unchainedshop/logger';
import moniker from 'moniker';
import { randomValueHex } from '@unchainedshop/utils';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

export default async function loginAsGuest(root: never, _: any, context: Context) {
log('mutation loginAsGuest');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { log } from '@unchainedshop/logger';
import { InvalidCredentialsError, UsernameOrEmailRequiredError } from '../../../errors.js';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

export default async function loginWithPassword(
root: never,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { log } from '@unchainedshop/logger';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

export default async function loginWithWebAuthn(
root: never,
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/resolvers/mutations/accounts/logout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { log } from '@unchainedshop/logger';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

export default async function logout(root: never, _: never, context: Context) {
const { userId } = context;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { log } from '@unchainedshop/logger';
import { UserNotFoundError } from '../../../errors.js';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

export default async function removeEmail(
root: never,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { log } from '@unchainedshop/logger';
import { UserWeb3AddressNotFoundError } from '../../../errors.js';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

export default async function removeWeb3Address(
root: never,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { log } from '@unchainedshop/logger';
import { UserWebAuthnCredentialsNotFoundError } from '../../../errors.js';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

export default async function removeWebAuthnCredentials(
root: never,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { log } from '@unchainedshop/logger';
import { InvalidResetTokenError, PasswordInvalidError } from '../../../errors.js';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

export default async function resetPassword(
root: never,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { log } from '@unchainedshop/logger';
import { UserNotFoundError } from '../../../errors.js';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

export default async function sendEnrollmentEmail(
root: never,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { log } from '@unchainedshop/logger';
import { UserNotFoundError } from '../../../errors.js';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

export default async function sendVerificationEmail(
root: never,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { log } from '@unchainedshop/logger';
import { UserNotFoundError, InvalidIdError, PasswordInvalidError } from '../../../errors.js';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

export default async function setPassword(
root: never,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { log } from '@unchainedshop/logger';
import { UserNotFoundError, InvalidIdError, UsernameAlreadyExistsError } from '../../../errors.js';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

export default async function setUsername(
root: never,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { log } from '@unchainedshop/logger';
import { InvalidEmailVerificationTokenError } from '../../../errors.js';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

export default async function verifyEmail(root: never, { token }: { token: any }, context: Context) {
const { modules, userId } = context;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { log } from '@unchainedshop/logger';
import { recoverPersonalSignature } from '@metamask/eth-sig-util';
import { UserWeb3AddressNotFoundError, UserWeb3AddressSignatureError } from '../../../errors.js';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

export default async function verifyWeb3Address(
root: never,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AssortmentFilter } from '@unchainedshop/core-assortments';
import { log } from '@unchainedshop/logger';
import { AssortmentNotFoundError, FilterNotFoundError, InvalidIdError } from '../../../errors.js';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

export default async function addAssortmentFilter(
root: never,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
CyclicAssortmentLinkNotSupportedError,
InvalidIdError,
} from '../../../errors.js';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

export default async function addAssortmentLink(
root: never,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { log } from '@unchainedshop/logger';
import { AssortmentProduct } from '@unchainedshop/core-assortments';
import { AssortmentNotFoundError, ProductNotFoundError, InvalidIdError } from '../../../errors.js';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

export default async function addAssortmentProduct(
root: never,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { log } from '@unchainedshop/logger';
import { Assortment, AssortmentText } from '@unchainedshop/core-assortments';
import { Context } from '../../../types.js';
import { Context } from '../../../context.js';

export default async function createAssortment(
root: never,
Expand Down
Loading

0 comments on commit 19ae1dc

Please sign in to comment.