Skip to content

Commit

Permalink
feat(core): Expose permitted Asset types in ServerConfig type
Browse files Browse the repository at this point in the history
Relates to #421
  • Loading branch information
michaelbromley committed Aug 18, 2020
1 parent 272b2db commit 66abc7f
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ export type Address = Node & {
phoneNumber?: Maybe<Scalars['String']>;
defaultShippingAddress?: Maybe<Scalars['Boolean']>;
defaultBillingAddress?: Maybe<Scalars['Boolean']>;
customFields?: Maybe<Scalars['JSON']>;
customFields?: Maybe<AddressCustomFields>;
};

export type AddressCustomFields = {
__typename?: 'AddressCustomFields';
instructions?: Maybe<Scalars['String']>;
verified?: Maybe<Scalars['Boolean']>;
};

export type Adjustment = {
Expand Down Expand Up @@ -416,6 +422,11 @@ export type CountryTranslationInput = {
name?: Maybe<Scalars['String']>;
};

export type CreateAddressCustomFieldsInput = {
instructions?: Maybe<Scalars['String']>;
verified?: Maybe<Scalars['Boolean']>;
};

export type CreateAddressInput = {
fullName?: Maybe<Scalars['String']>;
company?: Maybe<Scalars['String']>;
Expand All @@ -428,7 +439,7 @@ export type CreateAddressInput = {
phoneNumber?: Maybe<Scalars['String']>;
defaultShippingAddress?: Maybe<Scalars['Boolean']>;
defaultBillingAddress?: Maybe<Scalars['Boolean']>;
customFields?: Maybe<Scalars['JSON']>;
customFields?: Maybe<CreateAddressCustomFieldsInput>;
};

export type CreateAdministratorInput = {
Expand Down Expand Up @@ -2379,6 +2390,7 @@ export type OrderAddress = {
country?: Maybe<Scalars['String']>;
countryCode?: Maybe<Scalars['String']>;
phoneNumber?: Maybe<Scalars['String']>;
customFields?: Maybe<AddressCustomFields>;
};

export type OrderFilterParameter = {
Expand Down Expand Up @@ -3223,6 +3235,7 @@ export type SearchResultSortParameter = {
export type ServerConfig = {
__typename?: 'ServerConfig';
orderProcess: Array<OrderProcessState>;
permittedAssetTypes: Array<Scalars['String']>;
customFieldConfig: CustomFields;
};

Expand Down Expand Up @@ -3437,6 +3450,11 @@ export type TestShippingMethodResult = {
quote?: Maybe<TestShippingMethodQuote>;
};

export type UpdateAddressCustomFieldsInput = {
instructions?: Maybe<Scalars['String']>;
verified?: Maybe<Scalars['Boolean']>;
};

export type UpdateAddressInput = {
id: Scalars['ID'];
fullName?: Maybe<Scalars['String']>;
Expand All @@ -3450,7 +3468,7 @@ export type UpdateAddressInput = {
phoneNumber?: Maybe<Scalars['String']>;
defaultShippingAddress?: Maybe<Scalars['Boolean']>;
defaultBillingAddress?: Maybe<Scalars['Boolean']>;
customFields?: Maybe<Scalars['JSON']>;
customFields?: Maybe<UpdateAddressCustomFieldsInput>;
};

export type UpdateAdministratorInput = {
Expand Down
21 changes: 18 additions & 3 deletions packages/common/src/generated-shop-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ export type Address = Node & {
phoneNumber?: Maybe<Scalars['String']>;
defaultShippingAddress?: Maybe<Scalars['Boolean']>;
defaultBillingAddress?: Maybe<Scalars['Boolean']>;
customFields?: Maybe<Scalars['JSON']>;
customFields?: Maybe<AddressCustomFields>;
};

export type AddressCustomFields = {
__typename?: 'AddressCustomFields';
instructions?: Maybe<Scalars['String']>;
};

export type Adjustment = {
Expand Down Expand Up @@ -296,6 +301,10 @@ export type CountryTranslation = {
name: Scalars['String'];
};

export type CreateAddressCustomFieldsInput = {
instructions?: Maybe<Scalars['String']>;
};

export type CreateAddressInput = {
fullName?: Maybe<Scalars['String']>;
company?: Maybe<Scalars['String']>;
Expand All @@ -308,7 +317,7 @@ export type CreateAddressInput = {
phoneNumber?: Maybe<Scalars['String']>;
defaultShippingAddress?: Maybe<Scalars['Boolean']>;
defaultBillingAddress?: Maybe<Scalars['Boolean']>;
customFields?: Maybe<Scalars['JSON']>;
customFields?: Maybe<CreateAddressCustomFieldsInput>;
};

export type CreateCustomerInput = {
Expand Down Expand Up @@ -1622,6 +1631,7 @@ export type OrderAddress = {
country?: Maybe<Scalars['String']>;
countryCode?: Maybe<Scalars['String']>;
phoneNumber?: Maybe<Scalars['String']>;
customFields?: Maybe<AddressCustomFields>;
};

export type OrderFilterParameter = {
Expand Down Expand Up @@ -2200,6 +2210,7 @@ export type SearchResultSortParameter = {
export type ServerConfig = {
__typename?: 'ServerConfig';
orderProcess: Array<OrderProcessState>;
permittedAssetTypes: Array<Scalars['String']>;
customFieldConfig: CustomFields;
};

Expand Down Expand Up @@ -2327,6 +2338,10 @@ export type TaxRateList = PaginatedList & {
totalItems: Scalars['Int'];
};

export type UpdateAddressCustomFieldsInput = {
instructions?: Maybe<Scalars['String']>;
};

export type UpdateAddressInput = {
id: Scalars['ID'];
fullName?: Maybe<Scalars['String']>;
Expand All @@ -2340,7 +2355,7 @@ export type UpdateAddressInput = {
phoneNumber?: Maybe<Scalars['String']>;
defaultShippingAddress?: Maybe<Scalars['Boolean']>;
defaultBillingAddress?: Maybe<Scalars['Boolean']>;
customFields?: Maybe<Scalars['JSON']>;
customFields?: Maybe<UpdateAddressCustomFieldsInput>;
};

export type UpdateCustomerInput = {
Expand Down
24 changes: 21 additions & 3 deletions packages/common/src/generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ export type Address = Node & {
phoneNumber?: Maybe<Scalars['String']>;
defaultShippingAddress?: Maybe<Scalars['Boolean']>;
defaultBillingAddress?: Maybe<Scalars['Boolean']>;
customFields?: Maybe<Scalars['JSON']>;
customFields?: Maybe<AddressCustomFields>;
};

export type AddressCustomFields = {
__typename?: 'AddressCustomFields';
instructions?: Maybe<Scalars['String']>;
verified?: Maybe<Scalars['Boolean']>;
};

export type Adjustment = {
Expand Down Expand Up @@ -416,6 +422,11 @@ export type CountryTranslationInput = {
name?: Maybe<Scalars['String']>;
};

export type CreateAddressCustomFieldsInput = {
instructions?: Maybe<Scalars['String']>;
verified?: Maybe<Scalars['Boolean']>;
};

export type CreateAddressInput = {
fullName?: Maybe<Scalars['String']>;
company?: Maybe<Scalars['String']>;
Expand All @@ -428,7 +439,7 @@ export type CreateAddressInput = {
phoneNumber?: Maybe<Scalars['String']>;
defaultShippingAddress?: Maybe<Scalars['Boolean']>;
defaultBillingAddress?: Maybe<Scalars['Boolean']>;
customFields?: Maybe<Scalars['JSON']>;
customFields?: Maybe<CreateAddressCustomFieldsInput>;
};

export type CreateAdministratorInput = {
Expand Down Expand Up @@ -2467,6 +2478,7 @@ export type OrderAddress = {
country?: Maybe<Scalars['String']>;
countryCode?: Maybe<Scalars['String']>;
phoneNumber?: Maybe<Scalars['String']>;
customFields?: Maybe<AddressCustomFields>;
};

export type OrderFilterParameter = {
Expand Down Expand Up @@ -3349,6 +3361,7 @@ export type SearchResultSortParameter = {
export type ServerConfig = {
__typename?: 'ServerConfig';
orderProcess: Array<OrderProcessState>;
permittedAssetTypes: Array<Scalars['String']>;
customFieldConfig: CustomFields;
};

Expand Down Expand Up @@ -3562,6 +3575,11 @@ export type TestShippingMethodResult = {
quote?: Maybe<TestShippingMethodQuote>;
};

export type UpdateAddressCustomFieldsInput = {
instructions?: Maybe<Scalars['String']>;
verified?: Maybe<Scalars['Boolean']>;
};

export type UpdateAddressInput = {
id: Scalars['ID'];
fullName?: Maybe<Scalars['String']>;
Expand All @@ -3575,7 +3593,7 @@ export type UpdateAddressInput = {
phoneNumber?: Maybe<Scalars['String']>;
defaultShippingAddress?: Maybe<Scalars['Boolean']>;
defaultBillingAddress?: Maybe<Scalars['Boolean']>;
customFields?: Maybe<Scalars['JSON']>;
customFields?: Maybe<UpdateAddressCustomFieldsInput>;
};

export type UpdateAdministratorInput = {
Expand Down
24 changes: 21 additions & 3 deletions packages/core/e2e/graphql/generated-e2e-admin-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ export type Address = Node & {
phoneNumber?: Maybe<Scalars['String']>;
defaultShippingAddress?: Maybe<Scalars['Boolean']>;
defaultBillingAddress?: Maybe<Scalars['Boolean']>;
customFields?: Maybe<Scalars['JSON']>;
customFields?: Maybe<AddressCustomFields>;
};

export type AddressCustomFields = {
__typename?: 'AddressCustomFields';
instructions?: Maybe<Scalars['String']>;
verified?: Maybe<Scalars['Boolean']>;
};

export type Adjustment = {
Expand Down Expand Up @@ -416,6 +422,11 @@ export type CountryTranslationInput = {
name?: Maybe<Scalars['String']>;
};

export type CreateAddressCustomFieldsInput = {
instructions?: Maybe<Scalars['String']>;
verified?: Maybe<Scalars['Boolean']>;
};

export type CreateAddressInput = {
fullName?: Maybe<Scalars['String']>;
company?: Maybe<Scalars['String']>;
Expand All @@ -428,7 +439,7 @@ export type CreateAddressInput = {
phoneNumber?: Maybe<Scalars['String']>;
defaultShippingAddress?: Maybe<Scalars['Boolean']>;
defaultBillingAddress?: Maybe<Scalars['Boolean']>;
customFields?: Maybe<Scalars['JSON']>;
customFields?: Maybe<CreateAddressCustomFieldsInput>;
};

export type CreateAdministratorInput = {
Expand Down Expand Up @@ -2379,6 +2390,7 @@ export type OrderAddress = {
country?: Maybe<Scalars['String']>;
countryCode?: Maybe<Scalars['String']>;
phoneNumber?: Maybe<Scalars['String']>;
customFields?: Maybe<AddressCustomFields>;
};

export type OrderFilterParameter = {
Expand Down Expand Up @@ -3223,6 +3235,7 @@ export type SearchResultSortParameter = {
export type ServerConfig = {
__typename?: 'ServerConfig';
orderProcess: Array<OrderProcessState>;
permittedAssetTypes: Array<Scalars['String']>;
customFieldConfig: CustomFields;
};

Expand Down Expand Up @@ -3437,6 +3450,11 @@ export type TestShippingMethodResult = {
quote?: Maybe<TestShippingMethodQuote>;
};

export type UpdateAddressCustomFieldsInput = {
instructions?: Maybe<Scalars['String']>;
verified?: Maybe<Scalars['Boolean']>;
};

export type UpdateAddressInput = {
id: Scalars['ID'];
fullName?: Maybe<Scalars['String']>;
Expand All @@ -3450,7 +3468,7 @@ export type UpdateAddressInput = {
phoneNumber?: Maybe<Scalars['String']>;
defaultShippingAddress?: Maybe<Scalars['Boolean']>;
defaultBillingAddress?: Maybe<Scalars['Boolean']>;
customFields?: Maybe<Scalars['JSON']>;
customFields?: Maybe<UpdateAddressCustomFieldsInput>;
};

export type UpdateAdministratorInput = {
Expand Down
21 changes: 18 additions & 3 deletions packages/core/e2e/graphql/generated-e2e-shop-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ export type Address = Node & {
phoneNumber?: Maybe<Scalars['String']>;
defaultShippingAddress?: Maybe<Scalars['Boolean']>;
defaultBillingAddress?: Maybe<Scalars['Boolean']>;
customFields?: Maybe<Scalars['JSON']>;
customFields?: Maybe<AddressCustomFields>;
};

export type AddressCustomFields = {
__typename?: 'AddressCustomFields';
instructions?: Maybe<Scalars['String']>;
};

export type Adjustment = {
Expand Down Expand Up @@ -296,6 +301,10 @@ export type CountryTranslation = {
name: Scalars['String'];
};

export type CreateAddressCustomFieldsInput = {
instructions?: Maybe<Scalars['String']>;
};

export type CreateAddressInput = {
fullName?: Maybe<Scalars['String']>;
company?: Maybe<Scalars['String']>;
Expand All @@ -308,7 +317,7 @@ export type CreateAddressInput = {
phoneNumber?: Maybe<Scalars['String']>;
defaultShippingAddress?: Maybe<Scalars['Boolean']>;
defaultBillingAddress?: Maybe<Scalars['Boolean']>;
customFields?: Maybe<Scalars['JSON']>;
customFields?: Maybe<CreateAddressCustomFieldsInput>;
};

export type CreateCustomerInput = {
Expand Down Expand Up @@ -1622,6 +1631,7 @@ export type OrderAddress = {
country?: Maybe<Scalars['String']>;
countryCode?: Maybe<Scalars['String']>;
phoneNumber?: Maybe<Scalars['String']>;
customFields?: Maybe<AddressCustomFields>;
};

export type OrderFilterParameter = {
Expand Down Expand Up @@ -2200,6 +2210,7 @@ export type SearchResultSortParameter = {
export type ServerConfig = {
__typename?: 'ServerConfig';
orderProcess: Array<OrderProcessState>;
permittedAssetTypes: Array<Scalars['String']>;
customFieldConfig: CustomFields;
};

Expand Down Expand Up @@ -2327,6 +2338,10 @@ export type TaxRateList = PaginatedList & {
totalItems: Scalars['Int'];
};

export type UpdateAddressCustomFieldsInput = {
instructions?: Maybe<Scalars['String']>;
};

export type UpdateAddressInput = {
id: Scalars['ID'];
fullName?: Maybe<Scalars['String']>;
Expand All @@ -2340,7 +2355,7 @@ export type UpdateAddressInput = {
phoneNumber?: Maybe<Scalars['String']>;
defaultShippingAddress?: Maybe<Scalars['Boolean']>;
defaultBillingAddress?: Maybe<Scalars['Boolean']>;
customFields?: Maybe<Scalars['JSON']>;
customFields?: Maybe<UpdateAddressCustomFieldsInput>;
};

export type UpdateCustomerInput = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@ export class GlobalSettingsResolver {
serverConfig(): {
customFieldConfig: CustomFields;
orderProcess: OrderProcessState[];
permittedAssetTypes: string[];
} {
// Do not expose custom fields marked as "internal".
const exposedCustomFieldConfig: CustomFields = {};
for (const [entityType, customFields] of Object.entries(this.configService.customFields)) {
exposedCustomFieldConfig[entityType as keyof CustomFields] = customFields.filter(
(c) => !c.internal,
c => !c.internal,
);
}
return {
customFieldConfig: exposedCustomFieldConfig,
orderProcess: this.orderService.getOrderProcessStates(),
permittedAssetTypes: this.configService.assetOptions.permittedFileTypes,
};
}

Expand All @@ -58,12 +60,12 @@ export class GlobalSettingsResolver {
if (availableLanguages) {
const channels = await this.channelService.findAll();
const unavailableDefaults = channels.filter(
(c) => !availableLanguages.includes(c.defaultLanguageCode),
c => !availableLanguages.includes(c.defaultLanguageCode),
);
if (unavailableDefaults.length) {
throw new UserInputError('error.cannot-set-default-language-as-unavailable', {
language: unavailableDefaults.map((c) => c.defaultLanguageCode).join(', '),
channelCode: unavailableDefaults.map((c) => c.code).join(', '),
language: unavailableDefaults.map(c => c.defaultLanguageCode).join(', '),
channelCode: unavailableDefaults.map(c => c.code).join(', '),
});
}
}
Expand Down
Loading

0 comments on commit 66abc7f

Please sign in to comment.