@vtex/api 6.47.0 → 6.48.0
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.
- package/CHANGELOG.md +12 -0
- package/lib/clients/IOClients.d.ts +1 -2
- package/lib/clients/IOClients.js +0 -3
- package/lib/clients/infra/index.d.ts +0 -1
- package/lib/clients/infra/index.js +0 -1
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Auth.js +7 -7
- package/lib/utils/MineWinsConflictsResolver.d.ts +1 -0
- package/lib/utils/MineWinsConflictsResolver.js +11 -0
- package/package.json +1 -1
- package/lib/clients/infra/Metadata.d.ts +0 -26
- package/lib/clients/infra/Metadata.js +0 -83
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [6.48.0] - 2024-10-23
|
|
11
|
+
### Added
|
|
12
|
+
- resolveAll to `MineWinsConflictsResolver` to handle an array of conflicts.
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
- Avoid using async/await with then callbacks
|
|
16
|
+
- Bump semver from 5.7.1 to 5.7.2
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
- @auth: Validate token's `account` scope
|
|
20
|
+
- Delete Metadata client
|
|
21
|
+
|
|
10
22
|
## [6.47.0] - 2024-06-11
|
|
11
23
|
### Added
|
|
12
24
|
- Add option to save asynchronous cache
|
|
@@ -3,7 +3,7 @@ import { IOContext } from '../service/worker/runtime/typings';
|
|
|
3
3
|
import { Billing, Builder, MessagesGraphQL, Settings } from './apps';
|
|
4
4
|
import { CatalogGraphQL } from './apps/catalogGraphQL/index';
|
|
5
5
|
import { ID, MasterData, PaymentProvider } from './external';
|
|
6
|
-
import { Apps, Assets, BillingMetrics, Events,
|
|
6
|
+
import { Apps, Assets, BillingMetrics, Events, Registry, Router, VBase, Workspaces } from './infra';
|
|
7
7
|
import { IOClientConstructor } from './IOClient';
|
|
8
8
|
import { LicenseManager, Segment, Session, TenantClient } from './janus';
|
|
9
9
|
export declare type ClientsImplementation<T extends IOClients> = new (clientOptions: Record<string, InstanceOptions>, ctx: IOContext) => T;
|
|
@@ -22,7 +22,6 @@ export declare class IOClients {
|
|
|
22
22
|
get licenseManager(): LicenseManager;
|
|
23
23
|
get masterdata(): MasterData;
|
|
24
24
|
get messagesGraphQL(): MessagesGraphQL;
|
|
25
|
-
get metadata(): Metadata;
|
|
26
25
|
get registry(): Registry;
|
|
27
26
|
get router(): Router;
|
|
28
27
|
get segment(): Segment;
|
package/lib/clients/IOClients.js
CHANGED
|
@@ -41,9 +41,6 @@ class IOClients {
|
|
|
41
41
|
get messagesGraphQL() {
|
|
42
42
|
return this.getOrSet('messagesGraphQL', apps_1.MessagesGraphQL);
|
|
43
43
|
}
|
|
44
|
-
get metadata() {
|
|
45
|
-
return this.getOrSet('metadata', infra_1.Metadata);
|
|
46
|
-
}
|
|
47
44
|
get registry() {
|
|
48
45
|
return this.getOrSet('registry', infra_1.Registry);
|
|
49
46
|
}
|
|
@@ -9,7 +9,6 @@ __export(require("./BillingMetrics"));
|
|
|
9
9
|
__export(require("./Events"));
|
|
10
10
|
__export(require("./Housekeeper"));
|
|
11
11
|
__export(require("./InfraClient"));
|
|
12
|
-
__export(require("./Metadata"));
|
|
13
12
|
__export(require("./Registry"));
|
|
14
13
|
__export(require("./Router"));
|
|
15
14
|
__export(require("./VBase"));
|
|
@@ -7,7 +7,7 @@ const apollo_server_errors_1 = require("apollo-server-errors");
|
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
8
|
const graphql_1 = require("graphql");
|
|
9
9
|
const graphql_tools_1 = require("graphql-tools");
|
|
10
|
-
async function
|
|
10
|
+
async function parseIdToken(authToken, vtexIdToken) {
|
|
11
11
|
const url = `vtexid.vtex.com.br/api/vtexid/pub/authenticated/user?authToken=${vtexIdToken}`;
|
|
12
12
|
const req = await axios_1.default.request({
|
|
13
13
|
headers: {
|
|
@@ -21,7 +21,7 @@ async function getUserEmail(authToken, vtexIdToken) {
|
|
|
21
21
|
if (!req.data) {
|
|
22
22
|
return undefined;
|
|
23
23
|
}
|
|
24
|
-
return req.data
|
|
24
|
+
return { ...req.data };
|
|
25
25
|
}
|
|
26
26
|
async function getUserCanAccessResource(authToken, account, userEmail, productCode, resourceCode) {
|
|
27
27
|
const url = `http://${account}.vtexcommercestable.com.br/api/license-manager/pvt/accounts/${account}/products/${productCode}/logins/${userEmail}/resources/${resourceCode}/granted`;
|
|
@@ -37,13 +37,13 @@ async function getUserCanAccessResource(authToken, account, userEmail, productCo
|
|
|
37
37
|
async function auth(ctx, authArgs) {
|
|
38
38
|
const vtexIdToken = ctx.cookies.get('VtexIdclientAutCookie') || ctx.get('VtexIdclientAutCookie');
|
|
39
39
|
if (!vtexIdToken) {
|
|
40
|
-
throw new apollo_server_errors_1.
|
|
40
|
+
throw new apollo_server_errors_1.AuthenticationError('VtexIdclientAutCookie not found.');
|
|
41
41
|
}
|
|
42
|
-
const
|
|
43
|
-
if (!
|
|
44
|
-
throw new apollo_server_errors_1.
|
|
42
|
+
const parsedToken = await parseIdToken(ctx.vtex.authToken, vtexIdToken);
|
|
43
|
+
if (!parsedToken || parsedToken.account != ctx.vtex.account) {
|
|
44
|
+
throw new apollo_server_errors_1.AuthenticationError('Could not find user specified by VtexIdclientAutCookie.');
|
|
45
45
|
}
|
|
46
|
-
const userCanAccessResource = await getUserCanAccessResource(ctx.vtex.authToken, ctx.vtex.account,
|
|
46
|
+
const userCanAccessResource = await getUserCanAccessResource(ctx.vtex.authToken, ctx.vtex.account, parsedToken.user, authArgs.productCode, authArgs.resourceCode);
|
|
47
47
|
if (!userCanAccessResource) {
|
|
48
48
|
throw new apollo_server_errors_1.ForbiddenError('User indicated by VtexIdclientAutCookie is not authorized to access the indicated resource.');
|
|
49
49
|
}
|
|
@@ -13,6 +13,7 @@ export declare class MineWinsConflictsResolver<T> implements ConflictsResolver<T
|
|
|
13
13
|
private comparableKeys;
|
|
14
14
|
constructor(client: VBase, bucket: string, filePath: string, comparableKeys?: string[]);
|
|
15
15
|
resolve(logger?: Logger): Promise<any>;
|
|
16
|
+
resolveAll(): Promise<(Record<string, object | Record<string, object> | Record<string, object>[]> | Record<string, object>[])[]>;
|
|
16
17
|
protected mergeMineWins(base: Configuration, master: Configuration, mine: Configuration): Record<string, object | Record<string, object> | Record<string, object>[]> | Record<string, object>[];
|
|
17
18
|
private parseConflict;
|
|
18
19
|
private serializeContentByMimetype;
|
|
@@ -27,6 +27,17 @@ class MineWinsConflictsResolver {
|
|
|
27
27
|
return resolved;
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
|
+
async resolveAll() {
|
|
31
|
+
const conflictsResponse = await this.client.getConflicts(this.bucket);
|
|
32
|
+
const { data: conflicts } = conflictsResponse;
|
|
33
|
+
const resolvedConflicts = conflicts.map((conflict) => {
|
|
34
|
+
conflict.base.parsedContent = this.parseConflict(conflict.base);
|
|
35
|
+
conflict.master.parsedContent = this.parseConflict(conflict.master);
|
|
36
|
+
conflict.mine.parsedContent = this.parseConflict(conflict.mine);
|
|
37
|
+
return this.resolveConflictMineWins(conflict);
|
|
38
|
+
});
|
|
39
|
+
return resolvedConflicts;
|
|
40
|
+
}
|
|
30
41
|
mergeMineWins(base, master, mine) {
|
|
31
42
|
if (util_1.isArray(master)) {
|
|
32
43
|
return this.mergeMineWinsArray((base || []), master, (mine || []));
|
package/package.json
CHANGED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { InstanceOptions, RequestTracingConfig } from '../../HttpClient';
|
|
2
|
-
import { BucketMetadata } from '../../responses';
|
|
3
|
-
import { IOContext } from '../../service/worker/runtime/typings';
|
|
4
|
-
import { InfraClient } from './InfraClient';
|
|
5
|
-
export interface MetadataEntry {
|
|
6
|
-
Key: string;
|
|
7
|
-
Hash: string;
|
|
8
|
-
Value: any;
|
|
9
|
-
}
|
|
10
|
-
export interface MetadataEntryList {
|
|
11
|
-
Data: MetadataEntry[];
|
|
12
|
-
Next: string;
|
|
13
|
-
}
|
|
14
|
-
export declare class Metadata extends InfraClient {
|
|
15
|
-
constructor(context: IOContext, options?: InstanceOptions);
|
|
16
|
-
getBuckets: (bucket: string, tracingConfig?: RequestTracingConfig | undefined) => Promise<BucketMetadata>;
|
|
17
|
-
list: (bucket: string, includeValue: boolean, limit?: number | undefined, nextMarker?: string | undefined, tracingConfig?: RequestTracingConfig | undefined) => Promise<MetadataEntryList>;
|
|
18
|
-
listAll: (bucket: string, includeValue: boolean, tracingConfig?: RequestTracingConfig | undefined) => Promise<MetadataEntryList>;
|
|
19
|
-
get: (bucket: string, key: string, tracingConfig?: RequestTracingConfig | undefined) => Promise<any>;
|
|
20
|
-
save: (bucket: string, key: string, data: any, tracingConfig?: RequestTracingConfig | undefined) => Promise<void>;
|
|
21
|
-
saveAll: (bucket: string, data: {
|
|
22
|
-
[key: string]: any;
|
|
23
|
-
}, tracingConfig?: RequestTracingConfig | undefined) => Promise<void>;
|
|
24
|
-
delete: (bucket: string, key: string, tracingConfig?: RequestTracingConfig | undefined) => Promise<import("../../HttpClient").IOResponse<void>>;
|
|
25
|
-
deleteAll: (bucket: string, tracingConfig?: RequestTracingConfig | undefined) => Promise<import("../../HttpClient").IOResponse<void>>;
|
|
26
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const InfraClient_1 = require("./InfraClient");
|
|
4
|
-
const appId = process.env.VTEX_APP_ID;
|
|
5
|
-
const [runningAppName] = appId ? appId.split('@') : [''];
|
|
6
|
-
const routes = {
|
|
7
|
-
Bucket: (bucket) => `/buckets/${runningAppName}/${bucket}`,
|
|
8
|
-
Metadata: (bucket) => `${routes.Bucket(bucket)}/metadata`,
|
|
9
|
-
MetadataKey: (bucket, key) => `${routes.Metadata(bucket)}/${key}`,
|
|
10
|
-
};
|
|
11
|
-
class Metadata extends InfraClient_1.InfraClient {
|
|
12
|
-
constructor(context, options) {
|
|
13
|
-
super('router', context, options);
|
|
14
|
-
this.getBuckets = (bucket, tracingConfig) => {
|
|
15
|
-
const metric = 'meta-get-buckets';
|
|
16
|
-
return this.http.get(routes.Bucket(bucket), { metric, tracing: {
|
|
17
|
-
requestSpanNameSuffix: metric,
|
|
18
|
-
...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
|
|
19
|
-
} });
|
|
20
|
-
};
|
|
21
|
-
this.list = (bucket, includeValue, limit, nextMarker, tracingConfig) => {
|
|
22
|
-
const query = { value: includeValue, _limit: 10 };
|
|
23
|
-
if (limit && limit > 0) {
|
|
24
|
-
query._limit = limit;
|
|
25
|
-
}
|
|
26
|
-
if (nextMarker) {
|
|
27
|
-
query._marker = nextMarker;
|
|
28
|
-
}
|
|
29
|
-
const metric = 'meta-list';
|
|
30
|
-
return this.http.get(routes.Metadata(bucket), { metric, params: query, tracing: {
|
|
31
|
-
requestSpanNameSuffix: metric,
|
|
32
|
-
...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
|
|
33
|
-
} });
|
|
34
|
-
};
|
|
35
|
-
this.listAll = (bucket, includeValue, tracingConfig) => {
|
|
36
|
-
const query = { value: includeValue, _limit: 1000 };
|
|
37
|
-
const metric = 'meta-list-all';
|
|
38
|
-
return this.http.get(routes.Metadata(bucket), { metric, params: query, tracing: {
|
|
39
|
-
requestSpanNameSuffix: metric,
|
|
40
|
-
...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
|
|
41
|
-
} });
|
|
42
|
-
};
|
|
43
|
-
this.get = (bucket, key, tracingConfig) => {
|
|
44
|
-
const metric = 'meta-get';
|
|
45
|
-
return this.http.get(routes.MetadataKey(bucket, key), { metric, tracing: {
|
|
46
|
-
requestSpanNameSuffix: metric,
|
|
47
|
-
...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
|
|
48
|
-
} });
|
|
49
|
-
};
|
|
50
|
-
this.save = (bucket, key, data, tracingConfig) => {
|
|
51
|
-
const metric = 'meta-save';
|
|
52
|
-
return this.http.put(routes.MetadataKey(bucket, key), data, { metric, tracing: {
|
|
53
|
-
requestSpanNameSuffix: metric,
|
|
54
|
-
...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
|
|
55
|
-
} });
|
|
56
|
-
};
|
|
57
|
-
this.saveAll = (bucket, data, tracingConfig) => {
|
|
58
|
-
const metric = 'meta-save-all';
|
|
59
|
-
return this.http.put(routes.Metadata(bucket), data, { metric, tracing: {
|
|
60
|
-
requestSpanNameSuffix: metric,
|
|
61
|
-
...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
|
|
62
|
-
} });
|
|
63
|
-
};
|
|
64
|
-
this.delete = (bucket, key, tracingConfig) => {
|
|
65
|
-
const metric = 'meta-delete';
|
|
66
|
-
return this.http.delete(routes.MetadataKey(bucket, key), { metric, tracing: {
|
|
67
|
-
requestSpanNameSuffix: metric,
|
|
68
|
-
...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
|
|
69
|
-
} });
|
|
70
|
-
};
|
|
71
|
-
this.deleteAll = (bucket, tracingConfig) => {
|
|
72
|
-
const metric = 'meta-delete-all';
|
|
73
|
-
return this.http.delete(routes.Metadata(bucket), { metric, tracing: {
|
|
74
|
-
requestSpanNameSuffix: metric,
|
|
75
|
-
...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
|
|
76
|
-
} });
|
|
77
|
-
};
|
|
78
|
-
if (runningAppName === '') {
|
|
79
|
-
throw new Error(`Invalid path to access Metadata. Variable VTEX_APP_ID is not available.`);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
exports.Metadata = Metadata;
|