Skip to content

Commit 442addc

Browse files
committed
Merge remote-tracking branch 'origin/RVA/NLIC-1980/Group_models_&_packages_in_a_license_bundle'
# Conflicts: # dist/netlicensing-client.js # dist/netlicensing-client.min.js # dist/netlicensing-client.node.js # dist/netlicensing-client.node.min.js # src/Constants.js # src/index.js
2 parents 6c07c4e + abf44c8 commit 442addc

21 files changed

+3202
-2392
lines changed

dist/netlicensing-client.js

+1,282-1,119
Large diffs are not rendered by default.

dist/netlicensing-client.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/netlicensing-client.node.js

+1,335-1,172
Large diffs are not rendered by default.

dist/netlicensing-client.node.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Constants.js

+3-9
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,8 @@ export default {
206206
RED: 'RED',
207207
},
208208

209-
Notification: {
210-
ENDPOINT_PATH: 'notification',
211-
Type: {
212-
WEBHOOK: 'WEBHOOK',
213-
},
214-
Event: {
215-
CREATE_LICENSEE: 'CREATE_LICENSEE',
216-
CREATE_LICENSE: 'CREATE_LICENSE',
217-
},
209+
Bundle: {
210+
ENDPOINT_PATH: 'bundle',
211+
ENDPOINT_OBTAIN_PATH: 'obtain',
218212
},
219213
};

src/converters/itemToBundle.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import itemToObject from './itemToObject';
2+
import Bundle from '../entities/Bundle';
3+
4+
export default (item) => new Bundle(itemToObject(item));

src/entities/Bundle.js

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* @author Labs64 <[email protected]>
3+
* @license Apache-2.0
4+
* @link https://netlicensing.io
5+
* @copyright 2017 Labs64 NetLicensing
6+
*/
7+
8+
import BaseEntity from './BaseEntity';
9+
10+
/**
11+
* NetLicensing Bundle entity.
12+
*
13+
* Properties visible via NetLicensing API:
14+
*
15+
* Unique number that identifies the bundle. Vendor can assign this number when creating a bundle or
16+
* let NetLicensing generate one.
17+
* @property string number
18+
*
19+
* If set to false, the bundle is disabled.
20+
* @property boolean active
21+
*
22+
* Bundle name.
23+
* @property string name
24+
*
25+
* Arbitrary additional user properties of string type may be associated with each bundle. The name of user property
26+
* must not be equal to any of the fixed property names listed above and must be none of id, deleted.
27+
*
28+
* @constructor
29+
*/
30+
export default class Bundle extends BaseEntity {
31+
constructor(properties) {
32+
super({
33+
properties,
34+
// The attributes that should be cast to native types.
35+
casts: {
36+
number: 'string',
37+
active: 'boolean',
38+
name: 'string',
39+
},
40+
});
41+
}
42+
43+
setNumber(number) {
44+
return this.setProperty('number', number);
45+
}
46+
47+
getNumber(def) {
48+
return this.getProperty('number', def);
49+
}
50+
51+
setActive(active) {
52+
return this.setProperty('active', active);
53+
}
54+
55+
getActive(def) {
56+
return this.getProperty('active', def);
57+
}
58+
59+
setName(name) {
60+
return this.setProperty('name', name);
61+
}
62+
63+
getName(def) {
64+
return this.getProperty('name', def);
65+
}
66+
67+
setDescription(description) {
68+
return this.setProperty('description', description);
69+
}
70+
71+
getDescription(def) {
72+
return this.getProperty('description', def);
73+
}
74+
75+
setLicenseTemplateNumbers(licenseTemplateNumbers) {
76+
const numbers = (Array.isArray(licenseTemplateNumbers))
77+
? licenseTemplateNumbers.join(',')
78+
: licenseTemplateNumbers;
79+
80+
return this.setProperty('licenseTemplateNumbers', numbers);
81+
}
82+
83+
getLicenseTemplateNumbers(def) {
84+
const numbers = this.getProperty('licenseTemplateNumbers', def);
85+
return (numbers) ? numbers.split(',') : numbers;
86+
}
87+
88+
addLicenseTemplateNumber(licenseTemplateNumber) {
89+
const numbers = this.getLicenseTemplateNumbers([]);
90+
numbers.push(licenseTemplateNumber);
91+
92+
return this.setLicenseTemplateNumbers(numbers);
93+
}
94+
95+
removeLicenseTemplateNumber(licenseTemplateNumber) {
96+
const numbers = this.getLicenseTemplateNumbers([]);
97+
numbers.splice(numbers.indexOf(licenseTemplateNumber), 1);
98+
99+
return this.setLicenseTemplateNumbers(numbers);
100+
}
101+
}

src/index.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Context from './vo/Context';
66
import Page from './vo/Page';
77
import ValidationParameters from './vo/ValidationParameters';
88
import ValidationResults from './vo/ValidationResults';
9+
import BundleObtainParameters from './vo/BundleObtainParameters';
910

1011
// Services
1112
import Service from './services/Service';
@@ -18,7 +19,7 @@ import ProductService from './services/ProductService';
1819
import TokenService from './services/TokenService';
1920
import TransactionService from './services/TransactionService';
2021
import UtilityService from './services/UtilityService';
21-
import NotificationService from './services/NotificationService';
22+
import BundleService from './services/BundleService';
2223

2324
// Entities
2425
import BaseEntity from './entities/BaseEntity';
@@ -33,7 +34,7 @@ import ProductModule from './entities/ProductModule';
3334
import Token from './entities/Token';
3435
import Transaction from './entities/Transaction';
3536
import LicenseTransactionJoin from './entities/LicenseTransactionJoin';
36-
import Notification from './entities/Notification';
37+
import Bundle from './entities/Bundle';
3738

3839
// Converters
3940
import itemToCountry from './converters/itemToCountry';
@@ -46,7 +47,7 @@ import itemToProduct from './converters/itemToProduct';
4647
import itemToProductModule from './converters/itemToProductModule';
4748
import itemToToken from './converters/itemToToken';
4849
import itemToTransaction from './converters/itemToTransaction';
49-
import itemToNotification from './converters/itemToNotification';
50+
import itemToBundle from './converters/itemToBundle';
5051

5152
// Utils
5253
import CastsUtils from './util/CastsUtils';
@@ -67,6 +68,7 @@ export {
6768
Page,
6869
ValidationParameters,
6970
ValidationResults,
71+
BundleObtainParameters,
7072

7173
// Expose Services
7274
Service,
@@ -79,7 +81,7 @@ export {
7981
TokenService,
8082
TransactionService,
8183
UtilityService,
82-
NotificationService,
84+
BundleService,
8385

8486
// Expose Entities
8587
BaseEntity,
@@ -94,7 +96,7 @@ export {
9496
Token,
9597
Transaction,
9698
LicenseTransactionJoin,
97-
Notification,
99+
Bundle,
98100

99101
// Expose Converters
100102
itemToCountry,
@@ -107,7 +109,7 @@ export {
107109
itemToProductModule,
108110
itemToToken,
109111
itemToTransaction,
110-
itemToNotification,
112+
itemToBundle,
111113

112114
// Expose Utils
113115
CastsUtils,
@@ -117,3 +119,7 @@ export {
117119
// Errors
118120
NlicError,
119121
};
122+
123+
// module.exports = NetLicensing;
124+
125+
// Allow use of default import syntax in TypeScript

src/services/BundleService.js

+184
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
/**
2+
* @author Labs64 <[email protected]>
3+
* @license Apache-2.0
4+
* @link https://netlicensing.io
5+
* @copyright 2017 Labs64 NetLicensing
6+
*/
7+
8+
import Service from './Service';
9+
import Constants from '../Constants';
10+
import CheckUtils from '../util/CheckUtils';
11+
import FilterUtils from '../util/FilterUtils';
12+
import itemToBundle from '../converters/itemToBundle';
13+
import itemToLicense from '../converters/itemToLicense';
14+
import Page from '../vo/Page';
15+
16+
/**
17+
* JS representation of the Bundle Service. See NetLicensingAPI for details:
18+
* https://netlicensing.io/wiki/bundle-services
19+
*
20+
* @constructor
21+
*/
22+
23+
export default {
24+
/**
25+
* Creates new bundle with given properties.See NetLicensingAPI for details:
26+
* @see https://netlicensing.io/wiki/bundle-services#create-bundle
27+
*
28+
* determines the vendor on whose behalf the call is performed
29+
* @param context NetLicensing.Context
30+
*
31+
* non-null properties will be taken for the new object, null properties will either stay null, or will
32+
* be set to a default value, depending on property.
33+
* @param bundle NetLicensing.Bundle
34+
*
35+
* return the newly created bundle object in promise
36+
* @returns {Promise}
37+
*/
38+
39+
async create(context, bundle) {
40+
const { data: { items: { item: items } } } = await Service
41+
.post(context, Constants.Bundle.ENDPOINT_PATH, bundle.asPropertiesMap());
42+
43+
const [item] = items.filter(({ type }) => type === 'Bundle');
44+
45+
return itemToBundle(item);
46+
},
47+
48+
/**
49+
* Gets bundle by its number.See NetLicensingAPI for details:
50+
* @see https://netlicensing.io/wiki/bundle-services#get-bundle
51+
*
52+
* determines the vendor on whose behalf the call is performed
53+
* @param context NetLicensing.Context
54+
*
55+
* the bundle number
56+
* @param number string
57+
*
58+
* return the bundle object in promise
59+
* @returns {Promise}
60+
*/
61+
async get(context, number) {
62+
CheckUtils.paramNotEmpty(number, Constants.NUMBER);
63+
64+
const { data: { items: { item: items } } } = await Service
65+
.get(context, `${Constants.Bundle.ENDPOINT_PATH}/${number}`);
66+
67+
const [item] = items.filter(({ type }) => type === 'Bundle');
68+
69+
return itemToBundle(item);
70+
},
71+
72+
/**
73+
* Returns bundle of a vendor.See NetLicensingAPI for details:
74+
* @see https://netlicensing.io/wiki/bundle-services#bundles-list
75+
*
76+
* determines the vendor on whose behalf the call is performed
77+
* @param context NetLicensing.Context
78+
*
79+
* reserved for the future use, must be omitted / set to NULL
80+
* @param filter string|null
81+
*
82+
* array of bundle entities or empty array if nothing found in promise.
83+
* @returns {Promise}
84+
*/
85+
async list(context, filter) {
86+
const queryParams = {};
87+
88+
if (filter) {
89+
if (!CheckUtils.isValid(filter)) throw new TypeError(`filter has bad value ${filter}`);
90+
queryParams[Constants.FILTER] = typeof filter === 'string' ? filter : FilterUtils.encode(filter);
91+
}
92+
93+
const { data } = await Service.get(context, Constants.Bundle.ENDPOINT_PATH, queryParams);
94+
95+
return Page(
96+
data.items.item.filter(({ type }) => type === 'Bundle').map((v) => itemToBundle(v)),
97+
data.items.pagenumber,
98+
data.items.itemsnumber,
99+
data.items.totalpages,
100+
data.items.totalitems,
101+
);
102+
},
103+
104+
/**
105+
* Updates bundle properties.See NetLicensingAPI for details:
106+
* @see https://netlicensing.io/wiki/bundle-services#update-bundle
107+
*
108+
* determines the vendor on whose behalf the call is performed
109+
* @param context NetLicensing.Context
110+
*
111+
* bundle number
112+
* @param number string
113+
*
114+
* non-null properties will be updated to the provided values, null properties will stay unchanged.
115+
* @param bundle NetLicensing.Bundle
116+
*
117+
* updated bundle in promise.
118+
* @returns {Promise}
119+
*/
120+
async update(context, number, bundle) {
121+
CheckUtils.paramNotEmpty(number, Constants.NUMBER);
122+
123+
const { data: { items: { item: items } } } = await Service
124+
.post(context, `${Constants.Bundle.ENDPOINT_PATH}/${number}`, bundle.asPropertiesMap());
125+
126+
const [item] = items.filter(({ type }) => type === 'Bundle');
127+
128+
return itemToBundle(item);
129+
},
130+
131+
/**
132+
* Deletes bundle.See NetLicensingAPI for details:
133+
* @see https://netlicensing.io/wiki/bundle-services#delete-bundle
134+
*
135+
* determines the vendor on whose behalf the call is performed
136+
* @param context NetLicensing.Context
137+
*
138+
* bundle number
139+
* @param number string
140+
*
141+
* if true, any entities that depend on the one being deleted will be deleted too
142+
* @param forceCascade boolean
143+
*
144+
* return boolean state of delete in promise
145+
* @returns {Promise}
146+
*/
147+
delete(context, number, forceCascade) {
148+
CheckUtils.paramNotEmpty(number, Constants.NUMBER);
149+
150+
const queryParams = { forceCascade: Boolean(forceCascade) };
151+
152+
return Service.delete(context, `${Constants.Bundle.ENDPOINT_PATH}/${number}`, queryParams);
153+
},
154+
155+
/**
156+
* Obtain bundle.See NetLicensingAPI for details:
157+
* @see https://netlicensing.io/wiki/bundle-services#obtain-bundle
158+
*
159+
* determines the vendor on whose behalf the call is performed
160+
* @param context NetLicensing.Context
161+
*
162+
* bundle number
163+
* @param number string
164+
*
165+
* licensee number
166+
* @param bundleObtainParameters NetLicensing.BundleObtainParameters
167+
*
168+
* return array of licenses
169+
* @returns {Promise}
170+
*/
171+
async obtain(context, number, bundleObtainParameters) {
172+
CheckUtils.paramNotEmpty(number, Constants.NUMBER);
173+
CheckUtils.paramNotEmpty(bundleObtainParameters.getLicenseeNumber(), Constants.Licensee.LICENSEE_NUMBER);
174+
175+
const { ENDPOINT_PATH, ENDPOINT_OBTAIN_PATH } = Constants.Bundle;
176+
177+
const queryParams = { [Constants.Licensee.LICENSEE_NUMBER]: bundleObtainParameters.getLicenseeNumber() };
178+
179+
const { data: { items: { item: items } } } = await Service
180+
.post(context, `${ENDPOINT_PATH}/${number}/${ENDPOINT_OBTAIN_PATH}`, queryParams);
181+
182+
return items.filter(({ type }) => type === 'License').map((i) => itemToLicense(i));
183+
},
184+
};

0 commit comments

Comments
 (0)