Skip to content

Commit

Permalink
Merge pull request #773 from MoralisWeb3/feat/product-usage-tracking
Browse files Browse the repository at this point in the history
feat: Data tracking on Product usage
  • Loading branch information
sogunshola authored Oct 25, 2022
2 parents a7a75fa + f680257 commit 3be8ce6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
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

1 comment on commit 3be8ce6

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test coverage

Title Lines Statements Branches Functions
api-utils Coverage: 66%
66.56% (221/332) 50% (41/82) 68.05% (49/72)
auth Coverage: 97%
97.94% (143/146) 90.9% (20/22) 100% (42/42)
core Coverage: 89%
90.15% (568/630) 75.79% (119/157) 83.72% (108/129)
evm-api Coverage: 82%
80.72% (469/581) 17.57% (58/330) 66.32% (197/297)
evm-utils Coverage: 36%
36.68% (343/935) 39.17% (105/268) 28.26% (91/322)
sol-api Coverage: 75%
76.1% (86/113) 47.36% (9/19) 53.19% (25/47)
sol-utils Coverage: 82%
81.18% (82/101) 66.66% (12/18) 85.71% (30/35)
streams Coverage: 82%
82.72% (383/463) 64% (64/100) 72.72% (96/132)

Please sign in to comment.