@contrail/cli 3.6.0-alpha.eec506e → 3.6.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/README.md +182 -26
- package/dist/api/types.d.ts +35 -0
- package/dist/api/types.js +49 -1
- package/dist/auth/login.d.ts +0 -4
- package/dist/auth/login.js +52 -115
- package/dist/auth/login.spec.js +0 -100
- package/dist/basecommand.js +2 -2
- package/dist/commands/app/getApiKey.js +2 -2
- package/dist/commands/entities/create.d.ts +49 -0
- package/dist/commands/entities/create.js +618 -0
- package/dist/commands/entities/create.spec.js +581 -0
- package/dist/commands/entities/delete.d.ts +20 -0
- package/dist/commands/entities/delete.js +146 -0
- package/dist/commands/entities/get.d.ts +25 -0
- package/dist/commands/entities/get.js +298 -0
- package/dist/commands/entities/grammar.spec.d.ts +1 -0
- package/dist/commands/entities/grammar.spec.js +79 -0
- package/dist/commands/entities/output.spec.d.ts +1 -0
- package/dist/commands/entities/output.spec.js +72 -0
- package/dist/commands/entities/update.d.ts +32 -0
- package/dist/commands/entities/update.js +212 -0
- package/dist/commands/webhooks/delete.js +2 -3
- package/dist/common.d.ts +10 -1
- package/dist/common.js +37 -1
- package/dist/common.spec.d.ts +1 -0
- package/dist/common.spec.js +40 -0
- package/dist/helpers/config/config.d.ts +3 -3
- package/dist/helpers/config/config.js +3 -3
- package/dist/helpers/entities/assortment-items.d.ts +11 -0
- package/dist/helpers/entities/assortment-items.js +76 -0
- package/dist/helpers/entities/batchFetch.d.ts +11 -0
- package/dist/helpers/entities/batchFetch.js +50 -0
- package/dist/helpers/entities/index.d.ts +3 -0
- package/dist/helpers/entities/index.js +6 -0
- package/dist/helpers/entities/items.d.ts +6 -0
- package/dist/helpers/entities/items.js +60 -0
- package/dist/helpers/entities/items.spec.d.ts +1 -0
- package/dist/helpers/entities/items.spec.js +19 -0
- package/dist/helpers/entities/project-items.d.ts +2 -0
- package/dist/helpers/entities/project-items.js +44 -0
- package/dist/helpers/file-helpers.d.ts +1 -0
- package/dist/helpers/file-helpers.js +20 -3
- package/dist/helpers/propertySpecifications/dateRanges.d.ts +34 -0
- package/dist/helpers/propertySpecifications/dateRanges.js +91 -0
- package/dist/helpers/propertySpecifications/dateRanges.spec.d.ts +1 -0
- package/dist/helpers/propertySpecifications/dateRanges.spec.js +97 -0
- package/dist/helpers/propertySpecifications/propertySpecifications.d.ts +39 -0
- package/dist/helpers/propertySpecifications/propertySpecifications.js +102 -0
- package/dist/helpers/propertySpecifications/propertySpecifications.spec.d.ts +1 -0
- package/dist/helpers/propertySpecifications/propertySpecifications.spec.js +387 -0
- package/dist/helpers/propertySpecifications/propertyValues.d.ts +31 -0
- package/dist/helpers/propertySpecifications/propertyValues.js +132 -0
- package/dist/helpers/propertySpecifications/propertyValues.spec.d.ts +1 -0
- package/dist/helpers/propertySpecifications/propertyValues.spec.js +156 -0
- package/dist/logger.js +4 -1
- package/dist/logger.spec.d.ts +1 -0
- package/dist/logger.spec.js +12 -0
- package/node_modules/@contrail/entity-compare/package.json +6 -3
- package/node_modules/@contrail/loader/lib/common/conditional-columns.js +1 -1
- package/node_modules/@contrail/loader/lib/constants.d.ts +0 -8
- package/node_modules/@contrail/loader/lib/constants.js +1 -9
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.d.ts +0 -4
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.js +0 -57
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.spec.js +34 -492
- package/node_modules/@contrail/loader/lib/pipeline/validate.js +52 -2
- package/node_modules/@contrail/loader/lib/pipeline/validate.spec.js +85 -0
- package/node_modules/@contrail/loader/package.json +2 -2
- package/node_modules/@contrail/sdk/.github/workflows/publish-to-npm.yml +1 -4
- package/node_modules/@contrail/sdk/lib/auth/login.js +1 -1
- package/node_modules/@contrail/sdk/lib/config/config.d.ts +3 -0
- package/node_modules/@contrail/sdk/lib/config/config.js +13 -7
- package/node_modules/@contrail/sdk/lib/core/request.js +6 -2
- package/node_modules/@contrail/sdk/lib/entities/entities.client.d.ts +2 -0
- package/node_modules/@contrail/sdk/lib/entities/entities.client.js +3 -1
- package/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.js +1 -0
- package/node_modules/@contrail/sdk/lib/image-search/image-search.d.ts +34 -0
- package/node_modules/@contrail/sdk/lib/image-search/image-search.js +42 -0
- package/node_modules/@contrail/sdk/lib/image-search/index.d.ts +1 -0
- package/node_modules/@contrail/sdk/lib/image-search/index.js +17 -0
- package/node_modules/@contrail/sdk/lib/index.d.ts +1 -0
- package/node_modules/@contrail/sdk/lib/index.js +1 -0
- package/node_modules/@contrail/sdk/package.json +1 -1
- package/node_modules/@contrail/sdk/scripts/replicate-bug.js +69 -0
- package/oclif.manifest.json +449 -50
- package/package.json +6 -12
- package/dist/auth/sso.d.ts +0 -36
- package/dist/auth/sso.js +0 -174
- package/dist/auth/sso.spec.js +0 -148
- package/dist/commands/login.d.ts +0 -12
- package/dist/commands/login.js +0 -25
- /package/dist/{auth/sso.spec.d.ts → commands/entities/create.spec.d.ts} +0 -0
|
@@ -631,6 +631,91 @@ describe('validate', () => {
|
|
|
631
631
|
expect(issue).toBeUndefined();
|
|
632
632
|
});
|
|
633
633
|
});
|
|
634
|
+
describe('typePath format validation', () => {
|
|
635
|
+
const itemConfig = {
|
|
636
|
+
loadType: [types_1.LoadType.ITEM],
|
|
637
|
+
federatedMappings: { itemFamilyFederatedId: 'itemFamilyFederatedId', name: 'name' },
|
|
638
|
+
};
|
|
639
|
+
it('should error when rows have an invalid typePath', async () => {
|
|
640
|
+
const rows = [
|
|
641
|
+
{ itemFamilyFederatedId: 'fam-1', name: 'A', typePath: 'custom-entity:product' },
|
|
642
|
+
{ itemFamilyFederatedId: 'fam-2', name: 'B', typePath: 'item' },
|
|
643
|
+
];
|
|
644
|
+
const result = await (0, validate_1.validate)(rows, itemConfig, makeAnalysis());
|
|
645
|
+
const issue = result.issues.find((i) => i.columnName === 'typePath' && i.category === types_3.PreValidationCategory.MISSING_REQUIRED_FIELD);
|
|
646
|
+
expect(issue).toBeDefined();
|
|
647
|
+
expect(issue.affectedRows).toHaveLength(1);
|
|
648
|
+
expect(issue.affectedRows[0].row).toBe(2);
|
|
649
|
+
});
|
|
650
|
+
it('should error when typePath is missing on rows', async () => {
|
|
651
|
+
const rows = [
|
|
652
|
+
{ itemFamilyFederatedId: 'fam-1', name: 'A' },
|
|
653
|
+
{ itemFamilyFederatedId: 'fam-2', name: 'B' },
|
|
654
|
+
];
|
|
655
|
+
const result = await (0, validate_1.validate)(rows, itemConfig, makeAnalysis());
|
|
656
|
+
const issue = result.issues.find((i) => i.columnName === 'typePath' && i.category === types_3.PreValidationCategory.MISSING_REQUIRED_FIELD);
|
|
657
|
+
expect(issue).toBeDefined();
|
|
658
|
+
expect(issue.affectedRows).toHaveLength(2);
|
|
659
|
+
});
|
|
660
|
+
it('should not error when all rows have valid typePaths', async () => {
|
|
661
|
+
const rows = [
|
|
662
|
+
{ itemFamilyFederatedId: 'fam-1', name: 'A', typePath: 'item' },
|
|
663
|
+
{ itemFamilyFederatedId: 'fam-2', name: 'B', typePath: 'item:product' },
|
|
664
|
+
{ itemFamilyFederatedId: 'fam-3', name: 'C', typePath: 'item:material:fabric' },
|
|
665
|
+
];
|
|
666
|
+
const result = await (0, validate_1.validate)(rows, itemConfig, makeAnalysis());
|
|
667
|
+
const issue = result.issues.find((i) => i.columnName === 'typePath' && i.category === types_3.PreValidationCategory.MISSING_REQUIRED_FIELD);
|
|
668
|
+
expect(issue).toBeUndefined();
|
|
669
|
+
});
|
|
670
|
+
it('should not run for COLOR loads', async () => {
|
|
671
|
+
const colorConfig = {
|
|
672
|
+
loadType: [types_1.LoadType.COLOR],
|
|
673
|
+
federatedMappings: { federatedId: 'federatedId', name: 'name' },
|
|
674
|
+
};
|
|
675
|
+
const rows = [{ federatedId: '1', name: 'Red', typePath: 'bad-value' }];
|
|
676
|
+
const result = await (0, validate_1.validate)(rows, colorConfig, makeAnalysis());
|
|
677
|
+
const issue = result.issues.find((i) => i.columnName === 'typePath' && i.category === types_3.PreValidationCategory.MISSING_REQUIRED_FIELD);
|
|
678
|
+
expect(issue).toBeUndefined();
|
|
679
|
+
});
|
|
680
|
+
it('should not run for PROJECT_ITEM or ASSORTMENT loads (items already have a type)', async () => {
|
|
681
|
+
const projectItemConfig = {
|
|
682
|
+
loadType: [types_1.LoadType.PROJECT_ITEM, types_1.LoadType.ASSORTMENT],
|
|
683
|
+
federatedMappings: { itemFamilyFederatedId: 'itemFamilyFederatedId', name: 'name' },
|
|
684
|
+
};
|
|
685
|
+
const rows = [{ itemFamilyFederatedId: 'fam-1', name: 'A' }];
|
|
686
|
+
const result = await (0, validate_1.validate)(rows, projectItemConfig, makeAnalysis());
|
|
687
|
+
const issue = result.issues.find((i) => i.columnName === 'typePath' && i.category === types_3.PreValidationCategory.MISSING_REQUIRED_FIELD);
|
|
688
|
+
expect(issue).toBeUndefined();
|
|
689
|
+
});
|
|
690
|
+
it('should error for CUSTOM_ENTITY rows with missing subtype', async () => {
|
|
691
|
+
const customEntityConfig = {
|
|
692
|
+
loadType: [types_1.LoadType.CUSTOM_ENTITY],
|
|
693
|
+
federatedMappings: { federatedId: 'federatedId', name: 'name' },
|
|
694
|
+
};
|
|
695
|
+
const rows = [
|
|
696
|
+
{ federatedId: '1', name: 'A', typePath: 'custom-entity:material' },
|
|
697
|
+
{ federatedId: '2', name: 'B', typePath: 'custom-entity:' },
|
|
698
|
+
{ federatedId: '3', name: 'C' },
|
|
699
|
+
];
|
|
700
|
+
const result = await (0, validate_1.validate)(rows, customEntityConfig, makeAnalysis());
|
|
701
|
+
const issue = result.issues.find((i) => i.columnName === 'typePath' && i.category === types_3.PreValidationCategory.MISSING_REQUIRED_FIELD);
|
|
702
|
+
expect(issue).toBeDefined();
|
|
703
|
+
expect(issue.affectedRows).toHaveLength(2);
|
|
704
|
+
});
|
|
705
|
+
it('should not error for CUSTOM_ENTITY rows with valid typePath', async () => {
|
|
706
|
+
const customEntityConfig = {
|
|
707
|
+
loadType: [types_1.LoadType.CUSTOM_ENTITY],
|
|
708
|
+
federatedMappings: { federatedId: 'federatedId', name: 'name' },
|
|
709
|
+
};
|
|
710
|
+
const rows = [
|
|
711
|
+
{ federatedId: '1', name: 'A', typePath: 'custom-entity:material' },
|
|
712
|
+
{ federatedId: '2', name: 'B', typePath: 'custom-entity:material:fabric' },
|
|
713
|
+
];
|
|
714
|
+
const result = await (0, validate_1.validate)(rows, customEntityConfig, makeAnalysis());
|
|
715
|
+
const issue = result.issues.find((i) => i.columnName === 'typePath' && i.category === types_3.PreValidationCategory.MISSING_REQUIRED_FIELD);
|
|
716
|
+
expect(issue).toBeUndefined();
|
|
717
|
+
});
|
|
718
|
+
});
|
|
634
719
|
describe('typePath existence validation', () => {
|
|
635
720
|
it('should error when typesByPath contains entries with errors (non-existent type)', async () => {
|
|
636
721
|
const config = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/loader",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.10",
|
|
4
4
|
"description": "Client library for helping with loader jobs.",
|
|
5
5
|
"homepage": "https://archergreysorg.github.io/contrail-loader/",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"lib"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@contrail/entity-compare": "^1.
|
|
30
|
+
"@contrail/entity-compare": "^1.2.1",
|
|
31
31
|
"@contrail/entity-types": "1.6.1",
|
|
32
32
|
"@contrail/policies": "^2.0.7",
|
|
33
33
|
"@contrail/types": "^3.0.33",
|
|
@@ -15,7 +15,7 @@ const config_1 = require("../config");
|
|
|
15
15
|
const auth_1 = require("./auth");
|
|
16
16
|
const DEV_CONFIGURATION = {
|
|
17
17
|
userPoolId: 'us-east-1_e2cA0nJWu',
|
|
18
|
-
clientId: '
|
|
18
|
+
clientId: '209s9c62o165cqab0fu5ihjtu9',
|
|
19
19
|
apiGateway: 'https://api.dev.vibeiq.com/dev/api',
|
|
20
20
|
};
|
|
21
21
|
const PROD_CONFIGURATION = {
|
|
@@ -26,6 +26,9 @@ export interface ContrailConfig {
|
|
|
26
26
|
errorHandler?: ErrorHandler;
|
|
27
27
|
networkErrorHandler?: NetworkErrorHandler;
|
|
28
28
|
}
|
|
29
|
+
declare global {
|
|
30
|
+
var __CONTRAIL_SDK_CONFIG__: ContrailConfig | undefined;
|
|
31
|
+
}
|
|
29
32
|
export declare const CONTRAIL_CONFIG: ContrailConfig;
|
|
30
33
|
export declare function setConfig(config: ContrailConfig): void;
|
|
31
34
|
export declare function getConfig(): ContrailConfig;
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a, _b;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.getGlobalContext = exports.setGlobalContext = exports.setFromContext = exports.getConfig = exports.setConfig = exports.CONTRAIL_CONFIG = void 0;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
function getOrInitGlobalConfig() {
|
|
5
|
+
var _a, _b;
|
|
6
|
+
if (!globalThis.__CONTRAIL_SDK_CONFIG__) {
|
|
7
|
+
globalThis.__CONTRAIL_SDK_CONFIG__ = {
|
|
8
|
+
apiGateway: ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.API_GATEWAY) || 'http://localhost:3000/api',
|
|
9
|
+
orgId: (_b = process === null || process === void 0 ? void 0 : process.env) === null || _b === void 0 ? void 0 : _b.ORG_ID,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
return globalThis.__CONTRAIL_SDK_CONFIG__;
|
|
13
|
+
}
|
|
14
|
+
exports.CONTRAIL_CONFIG = getOrInitGlobalConfig();
|
|
9
15
|
function setConfig(config) {
|
|
10
|
-
Object.assign(
|
|
16
|
+
Object.assign(getOrInitGlobalConfig(), config);
|
|
11
17
|
}
|
|
12
18
|
exports.setConfig = setConfig;
|
|
13
19
|
function getConfig() {
|
|
14
|
-
return
|
|
20
|
+
return getOrInitGlobalConfig();
|
|
15
21
|
}
|
|
16
22
|
exports.getConfig = getConfig;
|
|
17
23
|
function setFromContext(ctx) {
|
|
@@ -114,7 +114,7 @@ class Request {
|
|
|
114
114
|
});
|
|
115
115
|
}
|
|
116
116
|
static requestWithRetries(resource, params, ctx) {
|
|
117
|
-
var _a;
|
|
117
|
+
var _a, _b;
|
|
118
118
|
return __awaiter(this, void 0, void 0, function* () {
|
|
119
119
|
const userCtx = ctx || (0, config_1.getGlobalContext)();
|
|
120
120
|
const start = new Date();
|
|
@@ -122,12 +122,13 @@ class Request {
|
|
|
122
122
|
const url = API_GATEWAY + resource;
|
|
123
123
|
const method = (params === null || params === void 0 ? void 0 : params.method) ? params.method.toUpperCase() : 'GET';
|
|
124
124
|
const fullResource = `${method} ${url.split('/')[3]}${resource}`;
|
|
125
|
+
const ignore404 = (_a = params === null || params === void 0 ? void 0 : params.ignore404) !== null && _a !== void 0 ? _a : false;
|
|
125
126
|
let res;
|
|
126
127
|
let attempt = 0;
|
|
127
128
|
while (attempt <= this.MAX_RETRIES) {
|
|
128
129
|
attempt++;
|
|
129
130
|
try {
|
|
130
|
-
if ((
|
|
131
|
+
if ((_b = userCtx === null || userCtx === void 0 ? void 0 : userCtx.requestOptions) === null || _b === void 0 ? void 0 : _b.useNativeFetch) {
|
|
131
132
|
res = yield globalThis.fetch(url, params);
|
|
132
133
|
}
|
|
133
134
|
else {
|
|
@@ -160,6 +161,9 @@ class Request {
|
|
|
160
161
|
else {
|
|
161
162
|
const error = yield res.text();
|
|
162
163
|
const errorJson = this.tryParseStringIntoObject(error);
|
|
164
|
+
if (ignore404 && res.status === 404) {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
163
167
|
const isTokenExpired = errorJson && typeof errorJson === 'object' && errorJson.errorCode === 'TOKEN_EXPIRED';
|
|
164
168
|
if (isTokenExpired) {
|
|
165
169
|
throw new ApiError('Token expired', errorJson, 'TOKEN_EXPIRED');
|
|
@@ -37,6 +37,7 @@ export declare abstract class EntitiesClientGetOptions {
|
|
|
37
37
|
suffix?: string;
|
|
38
38
|
skipHydrateRelationships?: boolean;
|
|
39
39
|
customParams?: Record<string, string | number | boolean>;
|
|
40
|
+
ignore404?: boolean;
|
|
40
41
|
}
|
|
41
42
|
export declare abstract class EntitiesClientCreateOptions {
|
|
42
43
|
entityName: string;
|
|
@@ -78,6 +79,7 @@ export declare abstract class EntitiesClientDeleteOptions {
|
|
|
78
79
|
relationId?: string;
|
|
79
80
|
apiVersion?: API_VERSION;
|
|
80
81
|
suffix?: string;
|
|
82
|
+
ignore404?: boolean;
|
|
81
83
|
}
|
|
82
84
|
export declare abstract class EntitiesClientBatchDeleteOptions {
|
|
83
85
|
entityName?: string;
|
|
@@ -134,7 +134,7 @@ class Entities {
|
|
|
134
134
|
resource += `ids=${options.federatedIds.map((id) => encodeURIComponent(id.replace(/,/g, '_COMMA_'))).join(',')}&`;
|
|
135
135
|
}
|
|
136
136
|
if (options.criteria) {
|
|
137
|
-
resource += 'criteria=' + JSURL.stringify(options.criteria);
|
|
137
|
+
resource += 'criteria=' + JSURL.stringify(options.criteria) + '&';
|
|
138
138
|
}
|
|
139
139
|
if (options.customParams) {
|
|
140
140
|
const buildQueryParam = (key, value) => {
|
|
@@ -154,6 +154,7 @@ class Entities {
|
|
|
154
154
|
}
|
|
155
155
|
return yield request_1.Request.request(resource, {
|
|
156
156
|
headers: Object.assign({}, getVersionHeader((_a = options.apiVersion) !== null && _a !== void 0 ? _a : this.apiVersion)),
|
|
157
|
+
ignore404: options.ignore404,
|
|
157
158
|
}, this.ctx);
|
|
158
159
|
});
|
|
159
160
|
}
|
|
@@ -269,6 +270,7 @@ class Entities {
|
|
|
269
270
|
return yield request_1.Request.request(resource, {
|
|
270
271
|
method: 'DELETE',
|
|
271
272
|
headers: Object.assign({ Accept: 'application/json', 'Content-Type': 'application/json' }, getVersionHeader((_a = options.apiVersion) !== null && _a !== void 0 ? _a : this.apiVersion)),
|
|
273
|
+
ignore404: options.ignore404,
|
|
272
274
|
}, this.ctx);
|
|
273
275
|
});
|
|
274
276
|
}
|
|
@@ -56,3 +56,4 @@ EntityResourceRegistry.registerEntityResourceName('project-configurator', 'proje
|
|
|
56
56
|
EntityResourceRegistry.registerEntityResourceName('identity', 'identities');
|
|
57
57
|
EntityResourceRegistry.registerEntityResourceName('entity-policy', 'entity-policies');
|
|
58
58
|
EntityResourceRegistry.registerEntityResourceName('measurement-spec-entry', 'measurement-spec-entries');
|
|
59
|
+
EntityResourceRegistry.registerEntityResourceName('image-search', 'image-search');
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { InvocationContext } from '../config';
|
|
2
|
+
export declare type ImageSearchSource = {
|
|
3
|
+
contentId: string;
|
|
4
|
+
} | {
|
|
5
|
+
fileId: string;
|
|
6
|
+
} | {
|
|
7
|
+
imageBase64: string;
|
|
8
|
+
};
|
|
9
|
+
export interface ImageSearchOptions {
|
|
10
|
+
limit?: number;
|
|
11
|
+
minScore?: number;
|
|
12
|
+
hydrate?: boolean;
|
|
13
|
+
filterContentIds?: string[];
|
|
14
|
+
}
|
|
15
|
+
export interface ImageSearchResult {
|
|
16
|
+
contentId: string;
|
|
17
|
+
fileId: string;
|
|
18
|
+
contentHolderReference: string;
|
|
19
|
+
fileName: string;
|
|
20
|
+
contentType: string;
|
|
21
|
+
primaryFileUrl: string;
|
|
22
|
+
score: number;
|
|
23
|
+
contentHolder?: Record<string, unknown>;
|
|
24
|
+
}
|
|
25
|
+
export interface ImageSearchResponse {
|
|
26
|
+
results: ImageSearchResult[];
|
|
27
|
+
}
|
|
28
|
+
export declare class ImageSearch {
|
|
29
|
+
private ctx;
|
|
30
|
+
constructor(ctx?: InvocationContext);
|
|
31
|
+
searchByText(query: string, options?: ImageSearchOptions): Promise<ImageSearchResponse>;
|
|
32
|
+
searchSimilar(source: ImageSearchSource, options?: ImageSearchOptions): Promise<ImageSearchResponse>;
|
|
33
|
+
private post;
|
|
34
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ImageSearch = void 0;
|
|
13
|
+
const request_1 = require("../core/request");
|
|
14
|
+
const SEARCH_RESOURCE = '/image-search/search';
|
|
15
|
+
const SEARCH_BY_IMAGE_RESOURCE = '/image-search/search-by-image';
|
|
16
|
+
class ImageSearch {
|
|
17
|
+
constructor(ctx) {
|
|
18
|
+
this.ctx = ctx;
|
|
19
|
+
}
|
|
20
|
+
searchByText(query, options = {}) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
return this.post(SEARCH_RESOURCE, Object.assign({ query }, options));
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
searchSimilar(source, options = {}) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
return this.post(SEARCH_BY_IMAGE_RESOURCE, Object.assign(Object.assign({}, source), options));
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
post(resource, body) {
|
|
31
|
+
var _a;
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const response = (yield request_1.Request.request(resource, {
|
|
34
|
+
method: 'POST',
|
|
35
|
+
body: JSON.stringify(body),
|
|
36
|
+
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
|
|
37
|
+
}, this.ctx));
|
|
38
|
+
return { results: (_a = response === null || response === void 0 ? void 0 : response.results) !== null && _a !== void 0 ? _a : [] };
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.ImageSearch = ImageSearch;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './image-search';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./image-search"), exports);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replication script for ENGINE-92:
|
|
3
|
+
* Auth credentials set on one @contrail/sdk instance don't propagate to a second instance
|
|
4
|
+
* loaded in the same process (npm link / prerelease version scenarios).
|
|
5
|
+
*
|
|
6
|
+
* Run: node scripts/replicate-bug.js
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const path = require('path');
|
|
10
|
+
|
|
11
|
+
const libDir = path.resolve(__dirname, '../lib');
|
|
12
|
+
const indexModulePath = path.join(libDir, 'index.js');
|
|
13
|
+
|
|
14
|
+
// ---------- Helper: load a fresh module instance ----------
|
|
15
|
+
function loadFreshInstance() {
|
|
16
|
+
// Clear all sdk lib modules from the require cache to simulate a second npm installation.
|
|
17
|
+
// Match on the resolved absolute lib path so this works regardless of directory name or OS path separator.
|
|
18
|
+
Object.keys(require.cache).forEach((key) => {
|
|
19
|
+
if (key.startsWith(libDir)) {
|
|
20
|
+
delete require.cache[key];
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return require(indexModulePath);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// ----------------------------------------------------------------
|
|
27
|
+
// SIMULATE the bug
|
|
28
|
+
// ----------------------------------------------------------------
|
|
29
|
+
|
|
30
|
+
console.log('\n======= ENGINE-92 Replication Script =======\n');
|
|
31
|
+
|
|
32
|
+
// Instance A = what @contrail/app-framework loads
|
|
33
|
+
const instanceA = loadFreshInstance();
|
|
34
|
+
|
|
35
|
+
// Instance B = what the app itself loads (separate npm copy)
|
|
36
|
+
const instanceB = loadFreshInstance();
|
|
37
|
+
|
|
38
|
+
const TEST_API_KEY = 'app:test-api-key-12345';
|
|
39
|
+
const TEST_ORG_SLUG = 'test-org';
|
|
40
|
+
|
|
41
|
+
// Step 1: App-framework calls setAppCredentials on its own SDK instance (A)
|
|
42
|
+
instanceA.setAppCredentials(TEST_API_KEY, TEST_ORG_SLUG);
|
|
43
|
+
|
|
44
|
+
// Step 2: App's own SDK reads config — this is what Request.getHeaders() does
|
|
45
|
+
const configFromB = instanceB.getConfig();
|
|
46
|
+
|
|
47
|
+
console.log('Credentials set via instance A (app-framework):');
|
|
48
|
+
console.log(' apiUserToken :', TEST_API_KEY);
|
|
49
|
+
console.log(' orgSlug :', TEST_ORG_SLUG);
|
|
50
|
+
console.log('');
|
|
51
|
+
console.log("Config read from instance B (app's SDK calls):");
|
|
52
|
+
console.log(' apiUserToken :', configFromB.apiUserToken ?? '(undefined)');
|
|
53
|
+
console.log(' orgSlug :', configFromB.orgSlug ?? '(undefined)');
|
|
54
|
+
console.log('');
|
|
55
|
+
|
|
56
|
+
const bugReproduced = configFromB.apiUserToken !== TEST_API_KEY;
|
|
57
|
+
|
|
58
|
+
if (bugReproduced) {
|
|
59
|
+
console.log('RESULT: BUG REPRODUCED ❌');
|
|
60
|
+
console.log(' Instance B cannot see credentials set by instance A.');
|
|
61
|
+
console.log(' This is why SDK calls fail with auth errors in event workflows.');
|
|
62
|
+
} else {
|
|
63
|
+
console.log('RESULT: Bug NOT reproduced — credentials ARE shared across instances ✅');
|
|
64
|
+
console.log(' (Either the fix is already applied, or the two instances resolved to the same module path.)');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
console.log('\n============================================\n');
|
|
68
|
+
|
|
69
|
+
process.exit(bugReproduced ? 1 : 0);
|