Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Data tracking on Product usage #773

Merged
merged 7 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/apiUtils/src/resolvers/EndpointResolver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MoralisCore, ApiErrorCode, Config, MoralisApiError, RequestController } from '@moralisweb3/core';
import { MoralisCore, ApiErrorCode, Config, MoralisApiError, RequestController, CoreConfig } from '@moralisweb3/core';
import { ApiConfig } from '../config/ApiConfig';
import { isNotFoundError } from '../errors/isNotFoundError';
import { ApiResultAdapter } from './ApiResultAdapter';
Expand Down Expand Up @@ -93,6 +93,7 @@ export class EndpointResolver<ApiParams, Params, ApiResult, AdaptedResult, JSONR

private createHeaders(): { [key: string]: string } {
const apiKey = this.config.get(ApiConfig.apiKey);
const product = this.config.get(CoreConfig.product);

if (!apiKey) {
throw new MoralisApiError({
Expand All @@ -107,6 +108,10 @@ export class EndpointResolver<ApiParams, Params, ApiResult, AdaptedResult, JSONR
headers['x-api-key'] = apiKey;
}

if (product) {
headers['x-moralis-product'] = product;
}

return headers;
}

Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/Config/CoreConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ export const CoreConfig = {
name: 'defaultNetwork',
defaultValue: 'Evm',
} as ConfigKey<Network>,

product: {
name: 'product',
defaultValue: undefined,
} as ConfigKey<string | undefined>,
};
1 change: 1 addition & 0 deletions packages/core/src/Config/CoreConfigSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export class CoreConfigSetup {
config.registerKey(CoreConfig.buidEnvironment);

config.registerKey(CoreConfig.defaultNetwork);
config.registerKey(CoreConfig.product);
}
}
2 changes: 1 addition & 1 deletion packages/core/src/Config/MoralisConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { EvmChainish } from './interfaces/EvmChainish';

// @moralisweb3/core
type CoreConfigType = typeof CoreConfig;
type CoreConfigValues = { [Key in keyof CoreConfigType]: CoreConfigType[Key]['defaultValue'] };
type CoreConfigValues = Omit<{ [Key in keyof CoreConfigType]: CoreConfigType[Key]['defaultValue'] }, 'product'>;

// @moralisweb3/evm-utils
interface EvmUtilsConfigValues {
Expand Down