@vtex/api 6.50.0-beta.2 → 7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- import { LogClient } from '@vtex/diagnostics-nodejs/dist/types';
2
- export declare function getLogClient(account: string, workspace: string, appName: string): Promise<LogClient>;
1
+ import { Types } from '@vtex/diagnostics-nodejs';
2
+ export declare function getLogClient(): Promise<Types.LogClient>;
@@ -1,45 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getLogClient = void 0;
4
- const diagnostics_nodejs_1 = require("@vtex/diagnostics-nodejs");
5
4
  const telemetry_1 = require("../telemetry");
6
- let logClient;
5
+ let client;
7
6
  let isInitializing = false;
8
7
  let initPromise = undefined;
9
- async function getLogClient(account, workspace, appName) {
10
- if (logClient) {
11
- return logClient;
8
+ async function getLogClient() {
9
+ if (client) {
10
+ return client;
12
11
  }
13
12
  if (initPromise) {
14
13
  return initPromise;
15
14
  }
16
15
  isInitializing = true;
17
- initPromise = initializeClient(account, workspace, appName);
16
+ initPromise = initializeClient();
18
17
  return initPromise;
19
18
  }
20
19
  exports.getLogClient = getLogClient;
21
- async function initializeClient(account, workspace, appName) {
20
+ async function initializeClient() {
22
21
  try {
23
- const telemetryClient = await (0, telemetry_1.getTelemetryClient)();
24
- const logsConfig = diagnostics_nodejs_1.Exporters.CreateLogsExporterConfig({
25
- endpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT,
26
- path: process.env.OTEL_EXPORTER_OTLP_PATH || '/v1/logs',
27
- protocol: 'http',
28
- interval: 5,
29
- timeoutSeconds: 5,
30
- headers: { 'Content-Type': 'application/json' },
31
- });
32
- const logsExporter = diagnostics_nodejs_1.Exporters.CreateExporter(logsConfig, 'otlp');
33
- await logsExporter.initialize();
34
- const clientKey = `${account}-${workspace}-${appName}`;
35
- logClient = await telemetryClient.newLogsClient({
36
- exporter: logsExporter,
37
- loggerName: `node-vtex-api-${clientKey}`,
38
- });
39
- return logClient;
22
+ const { logsClient } = await (0, telemetry_1.initializeTelemetry)();
23
+ client = logsClient;
24
+ initPromise = undefined;
25
+ return logsClient;
40
26
  }
41
27
  catch (error) {
42
28
  console.error('Failed to initialize logs client:', error);
29
+ initPromise = undefined;
43
30
  throw error;
44
31
  }
45
32
  finally {
@@ -89,7 +89,7 @@ class Logger {
89
89
  setTimeout(() => reject(new Error('Log client initialization timeout')), constants_1.LOG_CLIENT_INIT_TIMEOUT_MS);
90
90
  });
91
91
  this.logClient = await Promise.race([
92
- (0, client_1.getLogClient)(this.account, this.workspace, constants_1.APP.NAME),
92
+ (0, client_1.getLogClient)(),
93
93
  timeoutPromise
94
94
  ]);
95
95
  return this.logClient;
@@ -1,3 +1,9 @@
1
- import { TelemetryClient } from '@vtex/diagnostics-nodejs/dist/telemetry';
2
- export declare function getTelemetryClient(): Promise<TelemetryClient>;
3
- export declare function resetTelemetryClient(): void;
1
+ import { Logs, Metrics, Traces } from '@vtex/diagnostics-nodejs';
2
+ interface TelemetryClients {
3
+ logsClient: Logs.LogClient;
4
+ metricsClient: Metrics.MetricsClient;
5
+ tracesClient: Traces.TraceClient;
6
+ }
7
+ export declare function initializeTelemetry(): Promise<TelemetryClients>;
8
+ export declare function resetTelemetry(): void;
9
+ export {};
@@ -1,11 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resetTelemetryClient = exports.getTelemetryClient = void 0;
3
+ exports.resetTelemetry = exports.initializeTelemetry = void 0;
4
4
  const diagnostics_nodejs_1 = require("@vtex/diagnostics-nodejs");
5
5
  const constants_1 = require("../../constants");
6
+ const CLIENT_NAME = constants_1.APP.NAME || 'node-vtex-api';
7
+ const APPLICATION_ID = constants_1.APP.ID || 'vtex-io-app';
8
+ const EXPORTER_OTLP_ENDPOINT = process.env.EXPORTER_OTLP_ENDPOINT;
6
9
  class TelemetryClientSingleton {
7
10
  constructor() {
8
11
  this.initializationPromise = undefined;
12
+ this.initializeTracesClient = async (telemetryClient) => await telemetryClient.newTracesClient({
13
+ exporter: diagnostics_nodejs_1.Exporters.CreateExporter(diagnostics_nodejs_1.Exporters.CreateTracesExporterConfig({
14
+ endpoint: EXPORTER_OTLP_ENDPOINT,
15
+ }), 'otlp'),
16
+ });
17
+ this.initializeMetricsClient = async (telemetryClient) => await telemetryClient.newMetricsClient({
18
+ exporter: diagnostics_nodejs_1.Exporters.CreateExporter(diagnostics_nodejs_1.Exporters.CreateMetricsExporterConfig({
19
+ endpoint: EXPORTER_OTLP_ENDPOINT,
20
+ interval: 5,
21
+ timeoutSeconds: 5,
22
+ }), 'otlp'),
23
+ });
24
+ this.initializeLogsClient = async (telemetryClient) => await telemetryClient.newLogsClient({
25
+ exporter: diagnostics_nodejs_1.Exporters.CreateExporter(diagnostics_nodejs_1.Exporters.CreateLogsExporterConfig({
26
+ endpoint: EXPORTER_OTLP_ENDPOINT,
27
+ }), 'otlp'),
28
+ loggerName: `node-vtex-api-${APPLICATION_ID}`,
29
+ });
9
30
  }
10
31
  static getInstance() {
11
32
  if (!TelemetryClientSingleton.instance) {
@@ -13,45 +34,59 @@ class TelemetryClientSingleton {
13
34
  }
14
35
  return TelemetryClientSingleton.instance;
15
36
  }
16
- async initTelemetryClient() {
37
+ async initializeTelemetryClients() {
17
38
  try {
18
- const telemetryClient = await (0, diagnostics_nodejs_1.NewTelemetryClient)('node-vtex-api', constants_1.APP.ID || 'vtex-app', {
39
+ const telemetryClient = await (0, diagnostics_nodejs_1.NewTelemetryClient)(APPLICATION_ID, CLIENT_NAME, 'node-vtex-api', {
19
40
  additionalAttrs: {
20
41
  'version': constants_1.APP.VERSION || '',
21
42
  'environment': process.env.VTEX_WORKSPACE || 'development',
22
43
  },
23
44
  });
24
- this.telemetryClient = telemetryClient;
25
- return telemetryClient;
45
+ const [tracesClient, metricsClient, logsClient] = await Promise.all([
46
+ this.initializeTracesClient(telemetryClient),
47
+ this.initializeMetricsClient(telemetryClient),
48
+ this.initializeLogsClient(telemetryClient),
49
+ ]);
50
+ const instrumentations = [
51
+ ...diagnostics_nodejs_1.Instrumentation.CommonInstrumentations.minimal(),
52
+ ];
53
+ telemetryClient.registerInstrumentations(instrumentations);
54
+ const clients = {
55
+ logsClient,
56
+ metricsClient,
57
+ tracesClient,
58
+ };
59
+ this.telemetryClients = clients;
60
+ return clients;
26
61
  }
27
62
  catch (error) {
28
- console.error('Failed to initialize telemetry client:', error);
63
+ console.error('Failed to initialize telemetry clients:', error);
29
64
  throw error;
30
65
  }
31
66
  finally {
32
67
  this.initializationPromise = undefined;
33
68
  }
34
69
  }
35
- async getClient() {
36
- if (this.telemetryClient) {
37
- return this.telemetryClient;
70
+ async getTelemetryClients() {
71
+ if (this.telemetryClients) {
72
+ return this.telemetryClients;
38
73
  }
39
74
  if (this.initializationPromise) {
40
75
  return this.initializationPromise;
41
76
  }
42
- this.initializationPromise = this.initTelemetryClient();
77
+ this.initializationPromise = this.initializeTelemetryClients();
43
78
  return this.initializationPromise;
44
79
  }
45
80
  reset() {
46
- this.telemetryClient = undefined;
81
+ this.telemetryClients = undefined;
47
82
  this.initializationPromise = undefined;
48
83
  }
49
84
  }
50
- async function getTelemetryClient() {
51
- return TelemetryClientSingleton.getInstance().getClient();
85
+ async function initializeTelemetry() {
86
+ return TelemetryClientSingleton.getInstance().getTelemetryClients();
52
87
  }
53
- exports.getTelemetryClient = getTelemetryClient;
54
- function resetTelemetryClient() {
88
+ exports.initializeTelemetry = initializeTelemetry;
89
+ function resetTelemetry() {
55
90
  TelemetryClientSingleton.getInstance().reset();
56
91
  }
57
- exports.resetTelemetryClient = resetTelemetryClient;
92
+ exports.resetTelemetry = resetTelemetry;
@@ -3,4 +3,4 @@ import { SchemaDirectiveVisitor } from 'graphql-tools';
3
3
  export declare class Auth extends SchemaDirectiveVisitor {
4
4
  visitFieldDefinition(field: GraphQLField<any, any>): void;
5
5
  }
6
- export declare const authDirectiveTypeDefs = "\nenum Scope {\n PUBLIC\n PRIVATE\n}\n\ndirective @auth(\n scope: Scope\n productCode: String\n resourceCode: String\n) on FIELD_DEFINITION\n";
6
+ export declare const authDirectiveTypeDefs = "\ndirective @auth(\n productCode: String\n resourceCode: String\n) on FIELD_DEFINITION\n";
@@ -8,11 +8,6 @@ const apollo_server_errors_1 = require("apollo-server-errors");
8
8
  const axios_1 = __importDefault(require("axios"));
9
9
  const graphql_1 = require("graphql");
10
10
  const graphql_tools_1 = require("graphql-tools");
11
- var Scope;
12
- (function (Scope) {
13
- Scope["PUBLIC"] = "PUBLIC";
14
- Scope["PRIVATE"] = "PRIVATE";
15
- })(Scope || (Scope = {}));
16
11
  async function parseIdToken(authToken, vtexIdToken) {
17
12
  const url = `vtexid.vtex.com.br/api/vtexid/pub/authenticated/user?authToken=${vtexIdToken}`;
18
13
  const req = await axios_1.default.request({
@@ -56,7 +51,7 @@ async function auth(ctx, authArgs) {
56
51
  }
57
52
  function parseArgs(authArgs) {
58
53
  if (!authArgs.productCode || !authArgs.resourceCode) {
59
- throw new apollo_server_errors_1.UserInputError('Invalid auth schema directive args. Usage: @auth(scope: Scope, productCode: String, resourceCode: String).');
54
+ throw new apollo_server_errors_1.UserInputError('Invalid auth schema directive args. Usage: @auth(productCode: String, resourceCode: String).');
60
55
  }
61
56
  return authArgs;
62
57
  }
@@ -65,22 +60,14 @@ class Auth extends graphql_tools_1.SchemaDirectiveVisitor {
65
60
  const { resolve = graphql_1.defaultFieldResolver } = field;
66
61
  field.resolve = async (root, args, ctx, info) => {
67
62
  const authArgs = parseArgs(this.args);
68
- if (!authArgs.scope || authArgs.scope == Scope.PRIVATE) {
69
- await auth(ctx, authArgs);
70
- }
63
+ await auth(ctx, authArgs);
71
64
  return resolve(root, args, ctx, info);
72
65
  };
73
66
  }
74
67
  }
75
68
  exports.Auth = Auth;
76
69
  exports.authDirectiveTypeDefs = `
77
- enum Scope {
78
- PUBLIC
79
- PRIVATE
80
- }
81
-
82
70
  directive @auth(
83
- scope: Scope
84
71
  productCode: String
85
72
  resourceCode: String
86
73
  ) on FIELD_DEFINITION
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtex/api",
3
- "version": "6.50.0-beta.2",
3
+ "version": "7.0.1",
4
4
  "description": "VTEX I/O API client",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -49,7 +49,7 @@
49
49
  "dependencies": {
50
50
  "@types/koa": "^2.11.0",
51
51
  "@types/koa-compose": "^3.2.3",
52
- "@vtex/diagnostics-nodejs": "0.1.0-beta.10",
52
+ "@vtex/diagnostics-nodejs": "0.1.0-io-beta.19",
53
53
  "@vtex/node-error-report": "^0.0.3",
54
54
  "@wry/equality": "^0.1.9",
55
55
  "agentkeepalive": "^4.0.2",
@@ -124,5 +124,8 @@
124
124
  "typemoq": "^2.1.0",
125
125
  "typescript": "^4.4.4",
126
126
  "typescript-json-schema": "^0.52.0"
127
+ },
128
+ "resolutions": {
129
+ "@grpc/grpc-js": "^1.13.4"
127
130
  }
128
131
  }