@apex-actions/cli 0.75.0 → 0.76.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.
@@ -145,31 +145,38 @@ export class HttpLoginExchange {
145
145
  const body = (await response.json().catch(() => ({})));
146
146
  if (!response.ok)
147
147
  throw new Error(typeof body['error'] === 'string' ? body['error'] : `the code exchange failed with ${response.status}`);
148
- if (typeof body['login'] !== 'string' || typeof body['expiresAt'] !== 'string') {
149
- throw new Error('the control plane answered the code exchange without a token');
150
- }
151
- const str = (k) => {
152
- const v = body[k];
153
- return typeof v === 'string' ? { [k]: v } : {};
154
- };
155
- const list = (k) => {
156
- const v = body[k];
157
- return Array.isArray(v) ? { [k]: v.filter((r) => typeof r === 'string') } : {};
158
- };
159
- const source = body['source'];
160
- return {
161
- login: body['login'],
162
- expiresAt: body['expiresAt'],
163
- // An edit's answer carries no token: it changed one and minted nothing. The caller that needs one says so.
164
- ...str('token'),
165
- ...str('id'),
166
- ...str('name'),
167
- ...str('accountId'),
168
- ...str('last4'),
169
- ...str('createdAt'),
170
- ...list('repos'),
171
- ...list('permissions'),
172
- ...(source === 'dashboard' || source === 'login' || source === 'cli' ? { source } : {}),
173
- };
148
+ return redeemedFrom(body);
174
149
  }
175
150
  }
151
+ /**
152
+ * What `POST /api/v1/cli/token` minted, from its answer — shared by the loopback's redemption and the
153
+ * device flow's poll, which end in the same token. Throws when the answer names nobody.
154
+ */
155
+ export const redeemedFrom = (body) => {
156
+ if (typeof body['login'] !== 'string' || typeof body['expiresAt'] !== 'string') {
157
+ throw new Error('the control plane answered the code exchange without a token');
158
+ }
159
+ const str = (k) => {
160
+ const v = body[k];
161
+ return typeof v === 'string' ? { [k]: v } : {};
162
+ };
163
+ const list = (k) => {
164
+ const v = body[k];
165
+ return Array.isArray(v) ? { [k]: v.filter((r) => typeof r === 'string') } : {};
166
+ };
167
+ const source = body['source'];
168
+ return {
169
+ login: body['login'],
170
+ expiresAt: body['expiresAt'],
171
+ // An edit's answer carries no token: it changed one and minted nothing. The caller that needs one says so.
172
+ ...str('token'),
173
+ ...str('id'),
174
+ ...str('name'),
175
+ ...str('accountId'),
176
+ ...str('last4'),
177
+ ...str('createdAt'),
178
+ ...list('repos'),
179
+ ...list('permissions'),
180
+ ...(source === 'dashboard' || source === 'login' || source === 'cli' ? { source } : {}),
181
+ };
182
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apex-actions/cli",
3
- "version": "0.75.0",
3
+ "version": "0.76.0",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "//files": "Without this npm ships src, test and the CI config alongside the binary a user installs.",
6
6
  "files": [