@emilgroup/discount-sdk-node
Advanced tools
+44
-3
@@ -47,2 +47,12 @@ /* tslint:disable */ | ||
| export interface SwitchWorkspaceRequest { | ||
| username: string; | ||
| targetWorkspace: string; | ||
| } | ||
| export interface SwitchWorkspaceResponseClass { | ||
| accessToken: string; | ||
| permissions: string; | ||
| } | ||
| export enum Environment { | ||
@@ -98,3 +108,3 @@ Production = 'https://apiv2.emil.de', | ||
| async initialize(env: Environment = Environment.Production) { | ||
| async initialize(env: Environment = Environment.Production, targetWorkspace?: string) { | ||
| this.configuration.basePath = env; | ||
@@ -105,3 +115,3 @@ | ||
| if (this.username) { | ||
| await this.authorize(this.username, this.password); | ||
| await this.authorize(this.username, this.password, targetWorkspace); | ||
| this.password = null; // to avoid keeping password loaded in memory. | ||
@@ -156,3 +166,3 @@ } | ||
| async authorize(username: string, password: string): Promise<void> { | ||
| async authorize(username: string, password: string, targetWorkspace?: string): Promise<void> { | ||
| const options: AxiosRequestConfig = { | ||
@@ -177,4 +187,35 @@ method: 'POST', | ||
| this.configuration.refreshToken = refreshToken; | ||
| // Switch workspace if provided | ||
| if (targetWorkspace) { | ||
| await this.switchWorkspace(targetWorkspace); | ||
| } | ||
| } | ||
| async switchWorkspace(targetWorkspace: string): Promise<void> { | ||
| const options: AxiosRequestConfig = { | ||
| method: 'POST', | ||
| url: `${this.configuration.basePath}/authservice/v1/workspaces/switch`, | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| 'Authorization': `Bearer ${this.configuration.accessToken}`, | ||
| 'Cookie': this.configuration.refreshToken, | ||
| }, | ||
| data: { | ||
| username: this.configuration.username, | ||
| targetWorkspace, | ||
| } as SwitchWorkspaceRequest, | ||
| withCredentials: true, | ||
| }; | ||
| const response = await globalAxios.request<SwitchWorkspaceResponseClass>(options); | ||
| const { data: { accessToken } } = response; | ||
| this.configuration.accessToken = `Bearer ${accessToken}`; | ||
| const refreshToken = this.extractRefreshToken(response); | ||
| if (refreshToken) { | ||
| this.configuration.refreshToken = refreshToken; | ||
| } | ||
| } | ||
| async refreshTokenInternal(): Promise<string> { | ||
@@ -181,0 +222,0 @@ const { username, refreshToken } = this.configuration; |
@@ -717,3 +717,3 @@ /** | ||
| */ | ||
| createCampaign(requestParameters: CampaignsApiCreateCampaignRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<CreateCampaignResponseClass, any>>; | ||
| createCampaign(requestParameters: CampaignsApiCreateCampaignRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<CreateCampaignResponseClass, any, {}>>; | ||
| /** | ||
@@ -727,3 +727,3 @@ * Creates an account that is eligible to redeem a vouchers from a specific campaign. | ||
| */ | ||
| createEligibleAccount(requestParameters: CampaignsApiCreateEligibleAccountRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<CreateEligibleAccountResponseClass, any>>; | ||
| createEligibleAccount(requestParameters: CampaignsApiCreateEligibleAccountRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<CreateEligibleAccountResponseClass, any, {}>>; | ||
| /** | ||
@@ -737,3 +737,3 @@ * Removes a campaign and its associated vouchers. This will prevent any further voucher redemptions. | ||
| */ | ||
| deleteCampaign(requestParameters: CampaignsApiDeleteCampaignRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any>>; | ||
| deleteCampaign(requestParameters: CampaignsApiDeleteCampaignRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any, {}>>; | ||
| /** | ||
@@ -747,3 +747,3 @@ * Removes an eligible account from a campaign. This will prevent the account from using the assigned voucher code for discounts when the campaign is released. | ||
| */ | ||
| deleteEligibleAccount(requestParameters: CampaignsApiDeleteEligibleAccountRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any>>; | ||
| deleteEligibleAccount(requestParameters: CampaignsApiDeleteEligibleAccountRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any, {}>>; | ||
| /** | ||
@@ -757,3 +757,3 @@ * Removes all eligible accounts from a campaign. This will prevent these accounts from using their assigned voucher codes for discounts when the campaign is released. | ||
| */ | ||
| deleteEligibleAccounts(requestParameters: CampaignsApiDeleteEligibleAccountsRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any>>; | ||
| deleteEligibleAccounts(requestParameters: CampaignsApiDeleteEligibleAccountsRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any, {}>>; | ||
| /** | ||
@@ -767,3 +767,3 @@ * Retrieves detailed information about a specific campaign. | ||
| */ | ||
| getCampaign(requestParameters: CampaignsApiGetCampaignRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<GetCampaignResponseClass, any>>; | ||
| getCampaign(requestParameters: CampaignsApiGetCampaignRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<GetCampaignResponseClass, any, {}>>; | ||
| /** | ||
@@ -777,3 +777,3 @@ * Retrieves a list of campaigns. | ||
| */ | ||
| listCampaigns(requestParameters?: CampaignsApiListCampaignsRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<ListCampaignsResponseClass, any>>; | ||
| listCampaigns(requestParameters?: CampaignsApiListCampaignsRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<ListCampaignsResponseClass, any, {}>>; | ||
| /** | ||
@@ -787,3 +787,3 @@ * Retrieves a list of eligible accounts. | ||
| */ | ||
| listEligibleAccounts(requestParameters?: CampaignsApiListEligibleAccountsRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<ListEligibleAccountsResponseClass, any>>; | ||
| listEligibleAccounts(requestParameters?: CampaignsApiListEligibleAccountsRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<ListEligibleAccountsResponseClass, any, {}>>; | ||
| /** | ||
@@ -797,3 +797,3 @@ * Updates the data of an existing campaign. Only DRAFT campaigns can be updated. | ||
| */ | ||
| updateCampaign(requestParameters: CampaignsApiUpdateCampaignRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<UpdateCampaignResponseClass, any>>; | ||
| updateCampaign(requestParameters: CampaignsApiUpdateCampaignRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<UpdateCampaignResponseClass, any, {}>>; | ||
| /** | ||
@@ -807,3 +807,3 @@ * Updates the status of a campaign, which affects whether vouchers can be redeemed. | ||
| */ | ||
| updateCampaignStatus(requestParameters: CampaignsApiUpdateCampaignStatusRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any>>; | ||
| updateCampaignStatus(requestParameters: CampaignsApiUpdateCampaignStatusRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any, {}>>; | ||
| /** | ||
@@ -817,3 +817,3 @@ * Uploads accounts that are eligible to redeem vouchers from a specific campaign using a CSV file. The CSV file must contain a header row with the following columns: partnerNumber, voucherCode. Separate each column with a comma. | ||
| */ | ||
| uploadEligibleAccounts(requestParameters: CampaignsApiUploadEligibleAccountsRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any>>; | ||
| uploadEligibleAccounts(requestParameters: CampaignsApiUploadEligibleAccountsRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any, {}>>; | ||
| } |
@@ -69,3 +69,3 @@ /** | ||
| */ | ||
| check(options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<InlineResponse200, any>>; | ||
| check(options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<InlineResponse200, any, {}>>; | ||
| } |
@@ -491,3 +491,3 @@ /** | ||
| */ | ||
| chargePolicyVoucher(requestParameters: PolicyVouchersApiChargePolicyVoucherRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<ChargePolicyVoucherResponseClass, any>>; | ||
| chargePolicyVoucher(requestParameters: PolicyVouchersApiChargePolicyVoucherRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<ChargePolicyVoucherResponseClass, any, {}>>; | ||
| /** | ||
@@ -501,3 +501,3 @@ * This will check if the account is eligible for a specific voucher. | ||
| */ | ||
| checkAccountEligibility(requestParameters: PolicyVouchersApiCheckAccountEligibilityRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<CheckAccountEligibilityResponseClass, any>>; | ||
| checkAccountEligibility(requestParameters: PolicyVouchersApiCheckAccountEligibilityRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<CheckAccountEligibilityResponseClass, any, {}>>; | ||
| /** | ||
@@ -511,3 +511,3 @@ * This will create an policy voucher. | ||
| */ | ||
| createPolicyVoucher(requestParameters: PolicyVouchersApiCreatePolicyVoucherRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<CreatePolicyVoucherResponseClass, any>>; | ||
| createPolicyVoucher(requestParameters: PolicyVouchersApiCreatePolicyVoucherRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<CreatePolicyVoucherResponseClass, any, {}>>; | ||
| /** | ||
@@ -521,3 +521,3 @@ * This will delete an policy voucher. | ||
| */ | ||
| deletePolicyVoucher(requestParameters: PolicyVouchersApiDeletePolicyVoucherRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any>>; | ||
| deletePolicyVoucher(requestParameters: PolicyVouchersApiDeletePolicyVoucherRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any, {}>>; | ||
| /** | ||
@@ -531,3 +531,3 @@ * This will get an policy voucher. | ||
| */ | ||
| getPolicyVoucher(requestParameters: PolicyVouchersApiGetPolicyVoucherRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<GetPolicyVoucherResponseClass, any>>; | ||
| getPolicyVoucher(requestParameters: PolicyVouchersApiGetPolicyVoucherRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<GetPolicyVoucherResponseClass, any, {}>>; | ||
| /** | ||
@@ -541,3 +541,3 @@ * Returns a list of policy vouchers you have previously created. The policy vouchers are returned in sorted order, with the oldest one appearing first. For more information about pagination, read the Pagination documentation. | ||
| */ | ||
| listPolicyVouchers(requestParameters?: PolicyVouchersApiListPolicyVouchersRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<ListPolicyVouchersResponseClass, any>>; | ||
| listPolicyVouchers(requestParameters?: PolicyVouchersApiListPolicyVouchersRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<ListPolicyVouchersResponseClass, any, {}>>; | ||
| /** | ||
@@ -551,3 +551,3 @@ * This will redeem the policy voucher. | ||
| */ | ||
| redeemPolicyVoucher(requestParameters: PolicyVouchersApiRedeemPolicyVoucherRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<RedeemPolicyVoucherResponseClass, any>>; | ||
| redeemPolicyVoucher(requestParameters: PolicyVouchersApiRedeemPolicyVoucherRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<RedeemPolicyVoucherResponseClass, any, {}>>; | ||
| /** | ||
@@ -561,3 +561,3 @@ * This will withdraw the policy voucher. | ||
| */ | ||
| withdrawPolicyVoucher(requestParameters: PolicyVouchersApiWithdrawPolicyVoucherRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<WithdrawPolicyVoucherResponseClass, any>>; | ||
| withdrawPolicyVoucher(requestParameters: PolicyVouchersApiWithdrawPolicyVoucherRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<WithdrawPolicyVoucherResponseClass, any, {}>>; | ||
| } |
@@ -356,3 +356,3 @@ /** | ||
| */ | ||
| createVoucher(requestParameters: VouchersApiCreateVoucherRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<CreateVoucherResponseClass, any>>; | ||
| createVoucher(requestParameters: VouchersApiCreateVoucherRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<CreateVoucherResponseClass, any, {}>>; | ||
| /** | ||
@@ -366,3 +366,3 @@ * This will delete a voucher. | ||
| */ | ||
| deleteVoucher(requestParameters: VouchersApiDeleteVoucherRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any>>; | ||
| deleteVoucher(requestParameters: VouchersApiDeleteVoucherRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any, {}>>; | ||
| /** | ||
@@ -376,3 +376,3 @@ * This will get a voucher. | ||
| */ | ||
| getVoucher(requestParameters: VouchersApiGetVoucherRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<GetVoucherResponseClass, any>>; | ||
| getVoucher(requestParameters: VouchersApiGetVoucherRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<GetVoucherResponseClass, any, {}>>; | ||
| /** | ||
@@ -386,3 +386,3 @@ * Returns a list of Vouchers you have previously created. The Vouchers are returned in sorted order, with the oldest one appearing first. For more information about pagination, read the Pagination documentation. | ||
| */ | ||
| listVouchers(requestParameters?: VouchersApiListVouchersRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<ListVouchersResponseClass, any>>; | ||
| listVouchers(requestParameters?: VouchersApiListVouchersRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<ListVouchersResponseClass, any, {}>>; | ||
| /** | ||
@@ -396,3 +396,3 @@ * This will update a voucher. | ||
| */ | ||
| updateVoucher(requestParameters: VouchersApiUpdateVoucherRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<UpdateVoucherResponseClass, any>>; | ||
| updateVoucher(requestParameters: VouchersApiUpdateVoucherRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<UpdateVoucherResponseClass, any, {}>>; | ||
| } |
+11
-2
@@ -29,2 +29,10 @@ /** | ||
| } | ||
| export interface SwitchWorkspaceRequest { | ||
| username: string; | ||
| targetWorkspace: string; | ||
| } | ||
| export interface SwitchWorkspaceResponseClass { | ||
| accessToken: string; | ||
| permissions: string; | ||
| } | ||
| export declare enum Environment { | ||
@@ -59,3 +67,3 @@ Production = "https://apiv2.emil.de", | ||
| constructor(configuration?: Configuration, basePath?: string, axios?: AxiosInstance); | ||
| initialize(env?: Environment): Promise<void>; | ||
| initialize(env?: Environment, targetWorkspace?: string): Promise<void>; | ||
| private loadCredentials; | ||
@@ -65,3 +73,4 @@ private readConfigFile; | ||
| selectEnvironment(env: Environment): void; | ||
| authorize(username: string, password: string): Promise<void>; | ||
| authorize(username: string, password: string, targetWorkspace?: string): Promise<void>; | ||
| switchWorkspace(targetWorkspace: string): Promise<void>; | ||
| refreshTokenInternal(): Promise<string>; | ||
@@ -68,0 +77,0 @@ private extractRefreshToken; |
+42
-3
@@ -165,3 +165,3 @@ "use strict"; | ||
| } | ||
| BaseAPI.prototype.initialize = function (env) { | ||
| BaseAPI.prototype.initialize = function (env, targetWorkspace) { | ||
| if (env === void 0) { env = Environment.Production; } | ||
@@ -177,3 +177,3 @@ return __awaiter(this, void 0, void 0, function () { | ||
| if (!this.username) return [3 /*break*/, 3]; | ||
| return [4 /*yield*/, this.authorize(this.username, this.password)]; | ||
| return [4 /*yield*/, this.authorize(this.username, this.password, targetWorkspace)]; | ||
| case 2: | ||
@@ -248,3 +248,3 @@ _a.sent(); | ||
| }; | ||
| BaseAPI.prototype.authorize = function (username, password) { | ||
| BaseAPI.prototype.authorize = function (username, password, targetWorkspace) { | ||
| return __awaiter(this, void 0, void 0, function () { | ||
@@ -273,2 +273,41 @@ var options, response, accessToken, refreshToken; | ||
| this.configuration.refreshToken = refreshToken; | ||
| if (!targetWorkspace) return [3 /*break*/, 3]; | ||
| return [4 /*yield*/, this.switchWorkspace(targetWorkspace)]; | ||
| case 2: | ||
| _a.sent(); | ||
| _a.label = 3; | ||
| case 3: return [2 /*return*/]; | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
| BaseAPI.prototype.switchWorkspace = function (targetWorkspace) { | ||
| return __awaiter(this, void 0, void 0, function () { | ||
| var options, response, accessToken, refreshToken; | ||
| return __generator(this, function (_a) { | ||
| switch (_a.label) { | ||
| case 0: | ||
| options = { | ||
| method: 'POST', | ||
| url: "".concat(this.configuration.basePath, "/authservice/v1/workspaces/switch"), | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| 'Authorization': "Bearer ".concat(this.configuration.accessToken), | ||
| 'Cookie': this.configuration.refreshToken, | ||
| }, | ||
| data: { | ||
| username: this.configuration.username, | ||
| targetWorkspace: targetWorkspace, | ||
| }, | ||
| withCredentials: true, | ||
| }; | ||
| return [4 /*yield*/, axios_1.default.request(options)]; | ||
| case 1: | ||
| response = _a.sent(); | ||
| accessToken = response.data.accessToken; | ||
| this.configuration.accessToken = "Bearer ".concat(accessToken); | ||
| refreshToken = this.extractRefreshToken(response); | ||
| if (refreshToken) { | ||
| this.configuration.refreshToken = refreshToken; | ||
| } | ||
| return [2 /*return*/]; | ||
@@ -275,0 +314,0 @@ } |
+1
-1
@@ -66,3 +66,3 @@ /** | ||
| */ | ||
| export declare const createRequestFunction: (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) => <T = unknown, R = AxiosResponse<T, any>>(axios?: AxiosInstance, basePath?: string) => Promise<R>; | ||
| export declare const createRequestFunction: (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) => <T = unknown, R = AxiosResponse<T, any, {}>>(axios?: AxiosInstance, basePath?: string) => Promise<R>; | ||
| /** | ||
@@ -69,0 +69,0 @@ * EMIL DiscountService |
+2
-2
| { | ||
| "name": "@emilgroup/discount-sdk-node", | ||
| "version": "1.4.0", | ||
| "version": "1.4.1-beta.0", | ||
| "description": "OpenAPI client for @emilgroup/discount-sdk-node", | ||
@@ -21,3 +21,3 @@ "author": "OpenAPI-Generator Contributors", | ||
| "dependencies": { | ||
| "axios": "^0.27.2", | ||
| "axios": "^1.12.0", | ||
| "form-data": "^4.0.0", | ||
@@ -24,0 +24,0 @@ "url": "^0.11.0" |
+2
-2
@@ -20,7 +20,7 @@ # Emil Discount SDK | ||
| ``` | ||
| npm install @emilgroup/discount-sdk-node@1.4.0 --save | ||
| npm install @emilgroup/discount-sdk-node@1.4.1-beta.0 --save | ||
| ``` | ||
| or | ||
| ``` | ||
| yarn add @emilgroup/discount-sdk-node@1.4.0 | ||
| yarn add @emilgroup/discount-sdk-node@1.4.1-beta.0 | ||
| ``` | ||
@@ -27,0 +27,0 @@ |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
728976
0.54%14599
0.57%2
100%+ Added
+ Added
- Removed
Updated