@mondaydotcomorg/monday-authorization 3.5.0-feat-use-profile-for-graph-can-action-in-scope-f1451ab → 3.5.0-feat-shaime-support-entity-attributes-in-authorization-sdk-c9e4cfc
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/dist/attributions-service.d.ts.map +1 -1
- package/dist/attributions-service.js +1 -0
- package/dist/authorization-attributes-ms-service.d.ts +37 -0
- package/dist/authorization-attributes-ms-service.d.ts.map +1 -0
- package/dist/authorization-attributes-ms-service.js +232 -0
- package/dist/authorization-attributes-service.d.ts +45 -1
- package/dist/authorization-attributes-service.d.ts.map +1 -1
- package/dist/authorization-attributes-service.js +262 -0
- package/dist/clients/graph-api.d.ts.map +1 -1
- package/dist/clients/graph-api.js +0 -1
- package/dist/constants.d.ts +0 -3
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +0 -4
- package/dist/errors/argument-error.d.ts +4 -0
- package/dist/errors/argument-error.d.ts.map +1 -0
- package/dist/errors/argument-error.js +11 -0
- package/dist/esm/attributions-service.d.ts.map +1 -1
- package/dist/esm/attributions-service.mjs +1 -0
- package/dist/esm/authorization-attributes-ms-service.d.ts +37 -0
- package/dist/esm/authorization-attributes-ms-service.d.ts.map +1 -0
- package/dist/esm/authorization-attributes-ms-service.mjs +230 -0
- package/dist/esm/authorization-attributes-service.d.ts +45 -1
- package/dist/esm/authorization-attributes-service.d.ts.map +1 -1
- package/dist/esm/authorization-attributes-service.mjs +263 -1
- package/dist/esm/clients/graph-api.d.ts.map +1 -1
- package/dist/esm/clients/graph-api.mjs +1 -2
- package/dist/esm/constants.d.ts +0 -3
- package/dist/esm/constants.d.ts.map +1 -1
- package/dist/esm/constants.mjs +1 -5
- package/dist/esm/errors/argument-error.d.ts +4 -0
- package/dist/esm/errors/argument-error.d.ts.map +1 -0
- package/dist/esm/errors/argument-error.mjs +9 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.mjs +4 -0
- package/dist/esm/resource-attribute-assignment.d.ts +25 -0
- package/dist/esm/resource-attribute-assignment.d.ts.map +1 -0
- package/dist/esm/resource-attribute-assignment.mjs +60 -0
- package/dist/esm/resource-attributes-constants.d.ts +25 -0
- package/dist/esm/resource-attributes-constants.d.ts.map +1 -0
- package/dist/esm/resource-attributes-constants.mjs +25 -0
- package/dist/esm/types/authorization-attributes-contracts.d.ts +19 -3
- package/dist/esm/types/authorization-attributes-contracts.d.ts.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/resource-attribute-assignment.d.ts +25 -0
- package/dist/resource-attribute-assignment.d.ts.map +1 -0
- package/dist/resource-attribute-assignment.js +62 -0
- package/dist/resource-attributes-constants.d.ts +25 -0
- package/dist/resource-attributes-constants.d.ts.map +1 -0
- package/dist/resource-attributes-constants.js +28 -0
- package/dist/types/authorization-attributes-contracts.d.ts +19 -3
- package/dist/types/authorization-attributes-contracts.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/attributions-service.ts +4 -0
- package/src/authorization-attributes-ms-service.ts +327 -0
- package/src/authorization-attributes-service.ts +325 -0
- package/src/clients/graph-api.ts +1 -2
- package/src/constants.ts +0 -4
- package/src/errors/argument-error.ts +8 -0
- package/src/index.ts +16 -0
- package/src/resource-attribute-assignment.ts +70 -0
- package/src/resource-attributes-constants.ts +27 -0
- package/src/types/authorization-attributes-contracts.ts +49 -3
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ResourceType } from './resource-attributes-constants';
|
|
2
|
+
export declare class ResourceAttributeAssignment {
|
|
3
|
+
readonly resourceId: number;
|
|
4
|
+
readonly resourceType: ResourceType;
|
|
5
|
+
readonly attributeKey: string;
|
|
6
|
+
readonly attributeValue: string;
|
|
7
|
+
constructor(resourceId: number, resourceType: string, attributeKey: string, attributeValue: string);
|
|
8
|
+
/**
|
|
9
|
+
* Converts the assignment to hash format with camelCase keys
|
|
10
|
+
* @returns Object with camelCase keys: { resourceId, resourceType, key, value }
|
|
11
|
+
*/
|
|
12
|
+
toH(): {
|
|
13
|
+
resourceId: number;
|
|
14
|
+
resourceType: string;
|
|
15
|
+
key: string;
|
|
16
|
+
value: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Compares two assignments for equality
|
|
20
|
+
* @param other Another ResourceAttributeAssignment instance
|
|
21
|
+
* @returns true if all properties are equal
|
|
22
|
+
*/
|
|
23
|
+
equals(other: ResourceAttributeAssignment): boolean;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=resource-attribute-assignment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-attribute-assignment.d.ts","sourceRoot":"","sources":["../src/resource-attribute-assignment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAG/E,qBAAa,2BAA2B;IACtC,SAAgB,UAAU,EAAE,MAAM,CAAC;IACnC,SAAgB,YAAY,EAAE,YAAY,CAAC;IAC3C,SAAgB,YAAY,EAAE,MAAM,CAAC;IACrC,SAAgB,cAAc,EAAE,MAAM,CAAC;gBAE3B,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM;IA8BlG;;;OAGG;IACH,GAAG,IAAI;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;IAS/E;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,2BAA2B,GAAG,OAAO;CAWpD"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const resourceAttributesConstants = require('./resource-attributes-constants.js');
|
|
4
|
+
const errors_argumentError = require('./errors/argument-error.js');
|
|
5
|
+
|
|
6
|
+
class ResourceAttributeAssignment {
|
|
7
|
+
resourceId;
|
|
8
|
+
resourceType;
|
|
9
|
+
attributeKey;
|
|
10
|
+
attributeValue;
|
|
11
|
+
constructor(resourceId, resourceType, attributeKey, attributeValue) {
|
|
12
|
+
// Validate resourceId
|
|
13
|
+
if (!Number.isInteger(resourceId)) {
|
|
14
|
+
throw new errors_argumentError.ArgumentError(`resourceId must be an integer, got: ${resourceId}`);
|
|
15
|
+
}
|
|
16
|
+
// Validate resourceType
|
|
17
|
+
const validResourceTypes = Object.values(resourceAttributesConstants.RESOURCE_TYPES);
|
|
18
|
+
if (!validResourceTypes.includes(resourceType)) {
|
|
19
|
+
throw new errors_argumentError.ArgumentError(`resourceType must be one of [${validResourceTypes.join(', ')}], got: ${resourceType}`);
|
|
20
|
+
}
|
|
21
|
+
// Validate attributeKey
|
|
22
|
+
if (typeof attributeKey !== 'string') {
|
|
23
|
+
throw new errors_argumentError.ArgumentError(`attributeKey must be a string, got: ${typeof attributeKey}`);
|
|
24
|
+
}
|
|
25
|
+
// Validate attributeValue
|
|
26
|
+
if (typeof attributeValue !== 'string') {
|
|
27
|
+
throw new errors_argumentError.ArgumentError(`attributeValue must be a string, got: ${typeof attributeValue}`);
|
|
28
|
+
}
|
|
29
|
+
this.resourceId = resourceId;
|
|
30
|
+
this.resourceType = resourceType;
|
|
31
|
+
this.attributeKey = attributeKey;
|
|
32
|
+
this.attributeValue = attributeValue;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Converts the assignment to hash format with camelCase keys
|
|
36
|
+
* @returns Object with camelCase keys: { resourceId, resourceType, key, value }
|
|
37
|
+
*/
|
|
38
|
+
toH() {
|
|
39
|
+
return {
|
|
40
|
+
resourceId: this.resourceId,
|
|
41
|
+
resourceType: this.resourceType,
|
|
42
|
+
key: this.attributeKey,
|
|
43
|
+
value: this.attributeValue,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Compares two assignments for equality
|
|
48
|
+
* @param other Another ResourceAttributeAssignment instance
|
|
49
|
+
* @returns true if all properties are equal
|
|
50
|
+
*/
|
|
51
|
+
equals(other) {
|
|
52
|
+
if (!(other instanceof ResourceAttributeAssignment)) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return (this.resourceId === other.resourceId &&
|
|
56
|
+
this.resourceType === other.resourceType &&
|
|
57
|
+
this.attributeKey === other.attributeKey &&
|
|
58
|
+
this.attributeValue === other.attributeValue);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
exports.ResourceAttributeAssignment = ResourceAttributeAssignment;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare const RESOURCE_TYPES: {
|
|
2
|
+
readonly ACCOUNT: "account";
|
|
3
|
+
readonly ACCOUNT_PRODUCT: "account_product";
|
|
4
|
+
readonly WORKSPACE: "workspace";
|
|
5
|
+
readonly BOARD: "board";
|
|
6
|
+
readonly ITEM: "item";
|
|
7
|
+
readonly TEAM: "team";
|
|
8
|
+
readonly OVERVIEW: "overview";
|
|
9
|
+
readonly DOCUMENT: "document";
|
|
10
|
+
readonly CRM: "crm";
|
|
11
|
+
};
|
|
12
|
+
export declare const RESOURCE_ATTRIBUTES_CONSTANTS: {
|
|
13
|
+
readonly ACCOUNT_RESOURCE_ATTRIBUTES: {
|
|
14
|
+
readonly ENABLE_MEMBERS_INVITE_FROM_NON_AUTH_DOMAIN: "enable_members_invite_from_non_auth_domain";
|
|
15
|
+
};
|
|
16
|
+
readonly WORKSPACE_RESOURCE_ATTRIBUTES: {
|
|
17
|
+
readonly IS_DEFAULT_WORKSPACE: "is_default_workspace";
|
|
18
|
+
};
|
|
19
|
+
readonly BOARD_RESOURCE_ATTRIBUTES: {
|
|
20
|
+
readonly IS_SYNCABLE_CHILD_ENTITY: "is_syncable_child_entity";
|
|
21
|
+
readonly SYSTEM_ENTITY_TYPE: "system_entity_type";
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export type ResourceType = typeof RESOURCE_TYPES[keyof typeof RESOURCE_TYPES];
|
|
25
|
+
//# sourceMappingURL=resource-attributes-constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-attributes-constants.d.ts","sourceRoot":"","sources":["../src/resource-attributes-constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc;;;;;;;;;;CAUjB,CAAC;AAEX,eAAO,MAAM,6BAA6B;;;;;;;;;;;CAWhC,CAAC;AAEX,MAAM,MAAM,YAAY,GAAG,OAAO,cAAc,CAAC,MAAM,OAAO,cAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const RESOURCE_TYPES = {
|
|
4
|
+
ACCOUNT: 'account',
|
|
5
|
+
ACCOUNT_PRODUCT: 'account_product',
|
|
6
|
+
WORKSPACE: 'workspace',
|
|
7
|
+
BOARD: 'board',
|
|
8
|
+
ITEM: 'item',
|
|
9
|
+
TEAM: 'team',
|
|
10
|
+
OVERVIEW: 'overview',
|
|
11
|
+
DOCUMENT: 'document',
|
|
12
|
+
CRM: 'crm',
|
|
13
|
+
};
|
|
14
|
+
const RESOURCE_ATTRIBUTES_CONSTANTS = {
|
|
15
|
+
ACCOUNT_RESOURCE_ATTRIBUTES: {
|
|
16
|
+
ENABLE_MEMBERS_INVITE_FROM_NON_AUTH_DOMAIN: 'enable_members_invite_from_non_auth_domain',
|
|
17
|
+
},
|
|
18
|
+
WORKSPACE_RESOURCE_ATTRIBUTES: {
|
|
19
|
+
IS_DEFAULT_WORKSPACE: 'is_default_workspace',
|
|
20
|
+
},
|
|
21
|
+
BOARD_RESOURCE_ATTRIBUTES: {
|
|
22
|
+
IS_SYNCABLE_CHILD_ENTITY: 'is_syncable_child_entity',
|
|
23
|
+
SYSTEM_ENTITY_TYPE: 'system_entity_type',
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
exports.RESOURCE_ATTRIBUTES_CONSTANTS = RESOURCE_ATTRIBUTES_CONSTANTS;
|
|
28
|
+
exports.RESOURCE_TYPES = RESOURCE_TYPES;
|
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
import { Resource } from './general';
|
|
2
|
+
export type ResourceType = 'account' | 'account_product' | 'workspace' | 'board' | 'item' | 'team' | 'overview' | 'document' | 'crm';
|
|
3
|
+
export type EntityType = 'user' | 'team' | 'account';
|
|
4
|
+
export type CommonAttributeKey = string;
|
|
5
|
+
export type ResourceAttributeKey = string;
|
|
6
|
+
export type EntityAttributeKey = string;
|
|
7
|
+
export type ResourceAttributeKeyType = CommonAttributeKey | ResourceAttributeKey;
|
|
8
|
+
export type EntityAttributeKeyType = CommonAttributeKey | EntityAttributeKey;
|
|
2
9
|
export interface ResourceAttributeAssignment {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
key:
|
|
10
|
+
resourceId: number;
|
|
11
|
+
resourceType: ResourceType;
|
|
12
|
+
key: ResourceAttributeKeyType;
|
|
13
|
+
value: string;
|
|
14
|
+
}
|
|
15
|
+
export interface EntityAttributeAssignment {
|
|
16
|
+
entityId: number;
|
|
17
|
+
entityType: EntityType;
|
|
18
|
+
key: EntityAttributeKeyType;
|
|
6
19
|
value: string;
|
|
7
20
|
}
|
|
8
21
|
export interface ResourceAttributeResponse {
|
|
9
22
|
attributes: ResourceAttributeAssignment[];
|
|
10
23
|
}
|
|
24
|
+
export interface EntityAttributeResponse {
|
|
25
|
+
attributes: EntityAttributeAssignment[];
|
|
26
|
+
}
|
|
11
27
|
export interface ResourceAttributeDelete {
|
|
12
28
|
resourceType: Resource['type'];
|
|
13
29
|
resourceId: Resource['id'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization-attributes-contracts.d.ts","sourceRoot":"","sources":["../../src/types/authorization-attributes-contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"authorization-attributes-contracts.d.ts","sourceRoot":"","sources":["../../src/types/authorization-attributes-contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAGrC,MAAM,MAAM,YAAY,GACpB,SAAS,GACT,iBAAiB,GACjB,WAAW,GACX,OAAO,GACP,MAAM,GACN,MAAM,GACN,UAAU,GACV,UAAU,GACV,KAAK,CAAC;AAGV,MAAM,MAAM,UAAU,GAClB,MAAM,GACN,MAAM,GACN,SAAS,CAAC;AAGd,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAGxC,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAG1C,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAGxC,MAAM,MAAM,wBAAwB,GAAG,kBAAkB,GAAG,oBAAoB,CAAC;AACjF,MAAM,MAAM,sBAAsB,GAAG,kBAAkB,GAAG,kBAAkB,CAAC;AAG7E,MAAM,WAAW,2BAA2B;IAC1C,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,YAAY,CAAC;IAC3B,GAAG,EAAE,wBAAwB,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC;CACf;AAGD,MAAM,WAAW,yBAAyB;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,UAAU,CAAC;IACvB,GAAG,EAAE,sBAAsB,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC;CACf;AAGD,MAAM,WAAW,yBAAyB;IACxC,UAAU,EAAE,2BAA2B,EAAE,CAAC;CAC3C;AAED,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,yBAAyB,EAAE,CAAC;CACzC;AAGD,MAAM,WAAW,uBAAuB;IACtC,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC/B,UAAU,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC3B,GAAG,EAAE,MAAM,CAAC;CACb;AAED,oBAAY,8BAA8B;IACxC,MAAM,WAAW;IACjB,MAAM,WAAW;CAClB;AAED,UAAU,gCAAiC,SAAQ,2BAA2B;IAC5E,aAAa,EAAE,8BAA8B,CAAC,MAAM,CAAC;CACtD;AAED,UAAU,gCAAiC,SAAQ,uBAAuB;IACxE,aAAa,EAAE,8BAA8B,CAAC,MAAM,CAAC;CACtD;AAED,MAAM,MAAM,2BAA2B,GAAG,gCAAgC,GAAG,gCAAgC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mondaydotcomorg/monday-authorization",
|
|
3
|
-
"version": "3.5.0-feat-
|
|
3
|
+
"version": "3.5.0-feat-shaime-support-entity-attributes-in-authorization-sdk-c9e4cfc",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
@@ -53,6 +53,10 @@ export function getAttributionsFromApi(): { [key: string]: string } {
|
|
|
53
53
|
const runtimeAttributionsOutgoingHeaders = runtimeAttributions?.buildOutgoingHeaders('HTTP_INTERNAL');
|
|
54
54
|
|
|
55
55
|
if (!runtimeAttributionsOutgoingHeaders) {
|
|
56
|
+
logger.info(
|
|
57
|
+
{ tag: 'authorization-service', runtimeAttributionsOutgoingHeaders },
|
|
58
|
+
'No runtime attributions outgoing headers'
|
|
59
|
+
);
|
|
56
60
|
return callerAppNameFromSdk;
|
|
57
61
|
}
|
|
58
62
|
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { Api, HttpClient } from '@mondaydotcomorg/trident-backend-api';
|
|
2
|
+
import { signAuthorizationHeader } from '@mondaydotcomorg/monday-jwt';
|
|
3
|
+
import { HttpFetcherError } from '@mondaydotcomorg/monday-fetch-api';
|
|
4
|
+
import { ResourceAttributeAssignment } from './resource-attribute-assignment';
|
|
5
|
+
import { ArgumentError } from './errors/argument-error';
|
|
6
|
+
import { logger } from './authorization-internal-service';
|
|
7
|
+
import { getAttributionsFromApi } from './attributions-service';
|
|
8
|
+
import { AuthorizationInternalService } from './authorization-internal-service';
|
|
9
|
+
import { APP_NAME } from './constants';
|
|
10
|
+
|
|
11
|
+
const INTERNAL_APP_NAME = 'internal_ms';
|
|
12
|
+
const UPSERT_RESOURCE_ATTRIBUTES_PATH = '/attributes/{accountId}/resource';
|
|
13
|
+
const DELETE_RESOURCE_ATTRIBUTES_PATH = '/attributes/{accountId}/resource/{resourceType}/{resourceId}';
|
|
14
|
+
|
|
15
|
+
interface Resource {
|
|
16
|
+
resourceType: string;
|
|
17
|
+
resourceId: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface UpsertRequestBody {
|
|
21
|
+
resourceAttributeAssignments: Array<{
|
|
22
|
+
resourceId: number;
|
|
23
|
+
resourceType: string;
|
|
24
|
+
key: string;
|
|
25
|
+
value: string;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface DeleteRequestBody {
|
|
30
|
+
keys: string[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Service class for managing resource attributes in the authorization microservice.
|
|
35
|
+
* Provides synchronous HTTP operations to create/update and delete attributes on resources.
|
|
36
|
+
*/
|
|
37
|
+
export class AuthorizationAttributesMsService {
|
|
38
|
+
private static LOG_TAG = 'authorization_attributes_ms';
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Gets request headers including Authorization, Content-Type, and optional attribution headers
|
|
42
|
+
*/
|
|
43
|
+
private static getRequestHeaders(accountId: number, userId?: number): Record<string, string> {
|
|
44
|
+
const headers: Record<string, string> = {
|
|
45
|
+
'Content-Type': 'application/json',
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// Generate Authorization token
|
|
49
|
+
const authToken = signAuthorizationHeader({
|
|
50
|
+
appName: INTERNAL_APP_NAME,
|
|
51
|
+
accountId,
|
|
52
|
+
userId,
|
|
53
|
+
});
|
|
54
|
+
headers.Authorization = authToken;
|
|
55
|
+
|
|
56
|
+
// Add attribution headers if available
|
|
57
|
+
const attributionHeaders = getAttributionsFromApi();
|
|
58
|
+
for (const key in attributionHeaders) {
|
|
59
|
+
if (attributionHeaders.hasOwnProperty(key)) {
|
|
60
|
+
headers[key] = attributionHeaders[key];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Add X-REQUEST-ID if available from context
|
|
65
|
+
try {
|
|
66
|
+
const tridentContext = Api.getPart('context');
|
|
67
|
+
if (tridentContext?.runtimeAttributions) {
|
|
68
|
+
const outgoingHeaders = tridentContext.runtimeAttributions.buildOutgoingHeaders('HTTP_INTERNAL');
|
|
69
|
+
if (outgoingHeaders) {
|
|
70
|
+
const attributionHeadersMap: Record<string, string> = {};
|
|
71
|
+
for (const [key, value] of outgoingHeaders) {
|
|
72
|
+
attributionHeadersMap[key] = value;
|
|
73
|
+
}
|
|
74
|
+
if (attributionHeadersMap['x-request-id']) {
|
|
75
|
+
headers['X-REQUEST-ID'] = attributionHeadersMap['x-request-id'];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
} catch (error) {
|
|
80
|
+
// Silently fail if context is not available
|
|
81
|
+
logger.debug({ tag: this.LOG_TAG, error }, 'Failed to get request ID from context');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Add X-REQUEST-START timestamp
|
|
85
|
+
headers['X-REQUEST-START'] = Math.floor(Date.now() / 1000).toString();
|
|
86
|
+
|
|
87
|
+
return headers;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Validates that all messages are instances of the specified message class
|
|
92
|
+
*/
|
|
93
|
+
private static validateMessages<T>(
|
|
94
|
+
attributesMessages: T[],
|
|
95
|
+
messageClass: new (...args: any[]) => T
|
|
96
|
+
): void {
|
|
97
|
+
if (typeof messageClass !== 'function') {
|
|
98
|
+
throw new ArgumentError('messageClass must be a class/constructor function');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!Array.isArray(attributesMessages)) {
|
|
102
|
+
throw new ArgumentError('attributesMessages must be an array');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
for (let i = 0; i < attributesMessages.length; i++) {
|
|
106
|
+
if (!(attributesMessages[i] instanceof messageClass)) {
|
|
107
|
+
const className = (messageClass as any).name || 'ResourceAttributeAssignment';
|
|
108
|
+
throw new ArgumentError(
|
|
109
|
+
`All attributesMessages must be instances of ${className}, but item at index ${i} is not`
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Creates or updates resource attributes synchronously.
|
|
117
|
+
* @param accountId The account ID
|
|
118
|
+
* @param resourceAttributeAssignments Array of ResourceAttributeAssignment objects
|
|
119
|
+
* @returns Promise<void>
|
|
120
|
+
*/
|
|
121
|
+
static async upsertResourceAttributesSync(
|
|
122
|
+
accountId: number,
|
|
123
|
+
resourceAttributeAssignments: ResourceAttributeAssignment[]
|
|
124
|
+
): Promise<void> {
|
|
125
|
+
// Skip HTTP requests in test environment
|
|
126
|
+
if (process.env.NODE_ENV === 'test') {
|
|
127
|
+
logger.debug(
|
|
128
|
+
{ tag: this.LOG_TAG, accountId, count: resourceAttributeAssignments.length },
|
|
129
|
+
'Skipping upsertResourceAttributesSync in test environment'
|
|
130
|
+
);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Validate inputs
|
|
135
|
+
if (!Number.isInteger(accountId)) {
|
|
136
|
+
throw new ArgumentError(`accountId must be an integer, got: ${accountId}`);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (!Array.isArray(resourceAttributeAssignments)) {
|
|
140
|
+
throw new ArgumentError('resourceAttributeAssignments must be an array');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (resourceAttributeAssignments.length === 0) {
|
|
144
|
+
logger.warn({ tag: this.LOG_TAG, accountId }, 'upsertResourceAttributesSync called with empty array');
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Validate all assignments are instances of ResourceAttributeAssignment
|
|
149
|
+
this.validateMessages(resourceAttributeAssignments, ResourceAttributeAssignment);
|
|
150
|
+
|
|
151
|
+
// Convert assignments to hash format
|
|
152
|
+
const assignmentsHash = resourceAttributeAssignments.map(assignment => assignment.toH());
|
|
153
|
+
|
|
154
|
+
// Build request body
|
|
155
|
+
const requestBody: UpsertRequestBody = {
|
|
156
|
+
resourceAttributeAssignments: assignmentsHash,
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const httpClient = Api.getPart('httpClient');
|
|
160
|
+
if (!httpClient) {
|
|
161
|
+
throw new Error('AuthorizationAttributesMsService: HTTP client is not initialized');
|
|
162
|
+
}
|
|
163
|
+
const path = UPSERT_RESOURCE_ATTRIBUTES_PATH.replace('{accountId}', accountId.toString());
|
|
164
|
+
const headers = this.getRequestHeaders(accountId);
|
|
165
|
+
|
|
166
|
+
try {
|
|
167
|
+
logger.info(
|
|
168
|
+
{ tag: this.LOG_TAG, accountId, count: resourceAttributeAssignments.length },
|
|
169
|
+
'Upserting resource attributes'
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
await httpClient.fetch(
|
|
173
|
+
{
|
|
174
|
+
url: {
|
|
175
|
+
appName: APP_NAME,
|
|
176
|
+
path,
|
|
177
|
+
},
|
|
178
|
+
method: 'POST',
|
|
179
|
+
headers,
|
|
180
|
+
body: JSON.stringify(requestBody),
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
timeout: AuthorizationInternalService.getRequestTimeout(),
|
|
184
|
+
retryPolicy: AuthorizationInternalService.getRetriesPolicy(),
|
|
185
|
+
}
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
logger.info(
|
|
189
|
+
{ tag: this.LOG_TAG, accountId, count: resourceAttributeAssignments.length },
|
|
190
|
+
'Successfully upserted resource attributes'
|
|
191
|
+
);
|
|
192
|
+
} catch (err) {
|
|
193
|
+
logger.error(
|
|
194
|
+
{
|
|
195
|
+
tag: this.LOG_TAG,
|
|
196
|
+
accountId,
|
|
197
|
+
method: 'upsertResourceAttributesSync',
|
|
198
|
+
error: err instanceof Error ? err.message : String(err),
|
|
199
|
+
},
|
|
200
|
+
'Failed to upsert resource attributes'
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
if (err instanceof HttpFetcherError) {
|
|
204
|
+
throw new Error(
|
|
205
|
+
`AuthorizationAttributesMsService: [upsertResourceAttributesSync] request failed with status ${err.status}: ${err.message}`
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
throw err;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Deletes specific attributes from a resource synchronously.
|
|
214
|
+
* @param accountId The account ID
|
|
215
|
+
* @param resource Object with resourceType (string) and resourceId (number)
|
|
216
|
+
* @param attributeKeys Array of attribute key strings to delete
|
|
217
|
+
* @returns Promise<void>
|
|
218
|
+
*/
|
|
219
|
+
static async deleteResourceAttributesSync(
|
|
220
|
+
accountId: number,
|
|
221
|
+
resource: Resource,
|
|
222
|
+
attributeKeys: string[]
|
|
223
|
+
): Promise<void> {
|
|
224
|
+
// Skip HTTP requests in test environment
|
|
225
|
+
if (process.env.NODE_ENV === 'test') {
|
|
226
|
+
logger.debug(
|
|
227
|
+
{ tag: this.LOG_TAG, accountId, resource, attributeKeys },
|
|
228
|
+
'Skipping deleteResourceAttributesSync in test environment'
|
|
229
|
+
);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Validate inputs
|
|
234
|
+
if (!Number.isInteger(accountId)) {
|
|
235
|
+
throw new ArgumentError(`accountId must be an integer, got: ${accountId}`);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (!resource || typeof resource !== 'object') {
|
|
239
|
+
throw new ArgumentError('resource must be an object');
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (!Number.isInteger(resource.resourceId)) {
|
|
243
|
+
throw new ArgumentError(`resource.resourceId must be an integer, got: ${resource.resourceId}`);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (typeof resource.resourceType !== 'string') {
|
|
247
|
+
throw new ArgumentError(`resource.resourceType must be a string, got: ${typeof resource.resourceType}`);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (!Array.isArray(attributeKeys)) {
|
|
251
|
+
throw new ArgumentError('attributeKeys must be an array');
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (attributeKeys.length === 0) {
|
|
255
|
+
logger.warn({ tag: this.LOG_TAG, accountId, resource }, 'deleteResourceAttributesSync called with empty keys array');
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Validate all keys are strings
|
|
260
|
+
for (let i = 0; i < attributeKeys.length; i++) {
|
|
261
|
+
if (typeof attributeKeys[i] !== 'string') {
|
|
262
|
+
throw new ArgumentError(`All attributeKeys must be strings, but item at index ${i} is not`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Build request body
|
|
267
|
+
const requestBody: DeleteRequestBody = {
|
|
268
|
+
keys: attributeKeys,
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
const httpClient = Api.getPart('httpClient');
|
|
272
|
+
if (!httpClient) {
|
|
273
|
+
throw new Error('AuthorizationAttributesMsService: HTTP client is not initialized');
|
|
274
|
+
}
|
|
275
|
+
const path = DELETE_RESOURCE_ATTRIBUTES_PATH.replace('{accountId}', accountId.toString())
|
|
276
|
+
.replace('{resourceType}', resource.resourceType)
|
|
277
|
+
.replace('{resourceId}', resource.resourceId.toString());
|
|
278
|
+
const headers = this.getRequestHeaders(accountId);
|
|
279
|
+
|
|
280
|
+
try {
|
|
281
|
+
logger.info(
|
|
282
|
+
{ tag: this.LOG_TAG, accountId, resource, keys: attributeKeys },
|
|
283
|
+
'Deleting resource attributes'
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
await httpClient.fetch(
|
|
287
|
+
{
|
|
288
|
+
url: {
|
|
289
|
+
appName: APP_NAME,
|
|
290
|
+
path,
|
|
291
|
+
},
|
|
292
|
+
method: 'DELETE',
|
|
293
|
+
headers,
|
|
294
|
+
body: JSON.stringify(requestBody),
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
timeout: AuthorizationInternalService.getRequestTimeout(),
|
|
298
|
+
retryPolicy: AuthorizationInternalService.getRetriesPolicy(),
|
|
299
|
+
}
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
logger.info(
|
|
303
|
+
{ tag: this.LOG_TAG, accountId, resource, keys: attributeKeys },
|
|
304
|
+
'Successfully deleted resource attributes'
|
|
305
|
+
);
|
|
306
|
+
} catch (err) {
|
|
307
|
+
logger.error(
|
|
308
|
+
{
|
|
309
|
+
tag: this.LOG_TAG,
|
|
310
|
+
accountId,
|
|
311
|
+
method: 'deleteResourceAttributesSync',
|
|
312
|
+
resource,
|
|
313
|
+
error: err instanceof Error ? err.message : String(err),
|
|
314
|
+
},
|
|
315
|
+
'Failed to delete resource attributes'
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
if (err instanceof HttpFetcherError) {
|
|
319
|
+
throw new Error(
|
|
320
|
+
`AuthorizationAttributesMsService: [deleteResourceAttributesSync] request failed with status ${err.status}: ${err.message}`
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
throw err;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|