@govuk-pay/cli 0.0.72 → 0.0.74

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@govuk-pay/cli",
3
- "version": "0.0.72",
3
+ "version": "0.0.74",
4
4
  "description": "GOV.UK Pay Command Line Interface",
5
5
  "bin": {
6
6
  "pay": "bin/cli.js",
@@ -99,6 +99,16 @@ const appClient = {
99
99
  const typedBody = body;
100
100
  return typedBody;
101
101
  },
102
+ async getAccount(gatewayAccountId) {
103
+ const url = urlFor('connector', `/v1/api/accounts/${gatewayAccountId}`);
104
+ const result = await (0, fetch_wrapper_1.getRequest)(url);
105
+ if (!result.success) {
106
+ console.error((0, fetch_wrapper_1.formatErrorMessageForFailedRequest)(result.unsuccessfulResult));
107
+ return;
108
+ }
109
+ const body = result.successfulResult?.body;
110
+ return body;
111
+ },
102
112
  async setEmailCollectionModeOnAccount(accountID, emailCollectionMode) {
103
113
  const patchEmailCollectionModeData = {
104
114
  op: 'replace',
@@ -127,12 +137,14 @@ const appClient = {
127
137
  }
128
138
  return true;
129
139
  },
130
- async createToken(gatewayAccountID) {
140
+ async createToken(gatewayAccountID, serviceExternalId, serviceMode) {
131
141
  const createTokenData = {
132
142
  account_id: gatewayAccountID,
133
143
  description: 'my token',
134
144
  created_by: 'system generated',
135
- token_type: 'CARD'
145
+ token_type: 'CARD',
146
+ service_external_id: serviceExternalId,
147
+ service_mode: serviceMode
136
148
  };
137
149
  const url = urlFor('publicauth', '/v1/frontend/auth');
138
150
  const result = await (0, fetch_wrapper_1.postRequest)(url, createTokenData);
@@ -52,7 +52,7 @@ async function paymentHandler(argv) {
52
52
  console.error('Failed to create a fully set up account');
53
53
  return;
54
54
  }
55
- const createTokenResult = await app_client_js_1.default.createToken(account.gateway_account_id);
55
+ const createTokenResult = await app_client_js_1.default.createToken(account.gateway_account_id, serviceExternalID, account.type);
56
56
  if (createTokenResult === undefined) {
57
57
  console.error('Failed to create an api token');
58
58
  return;
@@ -26,6 +26,8 @@ async function tokenHandler(argv) {
26
26
  console.error('The publicauth service is unhealthy, so an API token cannot be created');
27
27
  return;
28
28
  }
29
+ let serviceExternalID;
30
+ let serviceMode;
29
31
  if (gatewayAccountID === undefined) {
30
32
  console.log('No gateway_account_id provided, creating service and gateway account');
31
33
  if (await app_client_js_1.default.isUnhealthy('adminusers')) {
@@ -36,7 +38,7 @@ async function tokenHandler(argv) {
36
38
  console.error('The connector service is unhealthy, so an API token cannot be created');
37
39
  return;
38
40
  }
39
- const serviceExternalID = await app_client_js_1.default.createService();
41
+ serviceExternalID = await app_client_js_1.default.createService();
40
42
  if (serviceExternalID === undefined) {
41
43
  console.error('Service creation failed');
42
44
  return;
@@ -46,9 +48,19 @@ async function tokenHandler(argv) {
46
48
  console.error('Failed to create a fully set up account');
47
49
  return;
48
50
  }
51
+ serviceMode = account.type;
49
52
  gatewayAccountID = account.gateway_account_id;
50
53
  }
51
- const token = await app_client_js_1.default.createToken(gatewayAccountID);
54
+ else {
55
+ const account = await app_client_js_1.default.getAccount(gatewayAccountID);
56
+ if (account === undefined) {
57
+ console.error(`No gateway account exists with ID: ${gatewayAccountID}`);
58
+ return;
59
+ }
60
+ serviceExternalID = account.service_id;
61
+ serviceMode = account.type;
62
+ }
63
+ const token = await app_client_js_1.default.createToken(gatewayAccountID, serviceExternalID, serviceMode);
52
64
  if (token === undefined) {
53
65
  console.error('Failed to create an API token');
54
66
  return;
@@ -43,7 +43,7 @@ async function userHandler(argv) {
43
43
  console.error('Failed to create a fully set up account');
44
44
  return;
45
45
  }
46
- const apiToken = await app_client_js_1.default.createToken(account.gateway_account_id);
46
+ const apiToken = await app_client_js_1.default.createToken(account.gateway_account_id, serviceExternalID, account.type);
47
47
  if (apiToken === undefined) {
48
48
  console.error('Failed to create an API token');
49
49
  return;