@baukit/suite-client 0.19.1 → 0.20.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.
- package/dist/api.d.ts +11 -12
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +22 -14
- package/dist/api.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/responses.d.ts +26 -0
- package/dist/responses.d.ts.map +1 -0
- package/dist/responses.js +101 -0
- package/dist/responses.js.map +1 -0
- package/package.json +4 -4
- package/src/api.ts +55 -22
- package/src/client.test.ts +11 -21
- package/src/index.ts +1 -0
- package/src/responses.test.ts +89 -0
- package/src/responses.ts +133 -0
package/dist/api.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type SuiteLinkStart, type SuiteRedirect } from './responses.js';
|
|
1
2
|
export type RewardMode = 'native' | 'source_xp' | 'off';
|
|
2
3
|
export type DeliveryHealth = 'healthy' | 'degraded' | 'needs_attention' | 'disabled';
|
|
3
4
|
export interface SuiteLink {
|
|
@@ -56,9 +57,12 @@ export interface SuiteDelivery {
|
|
|
56
57
|
readonly createdAt: string;
|
|
57
58
|
readonly updatedAt: string;
|
|
58
59
|
}
|
|
59
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* Supply the product's authenticated, JSON-decoding HTTP transport. Return the decoded body
|
|
62
|
+
* untyped; SuiteClient validates every response and throws SuiteResponseError on a mismatch.
|
|
63
|
+
*/
|
|
60
64
|
export interface SuiteTransport {
|
|
61
|
-
request
|
|
65
|
+
request(method: 'GET' | 'POST' | 'PATCH' | 'DELETE', path: string, body?: unknown): Promise<unknown>;
|
|
62
66
|
}
|
|
63
67
|
export declare class SuiteFlowError extends Error {
|
|
64
68
|
readonly code: string;
|
|
@@ -73,6 +77,8 @@ export declare function suiteErrorCode(error: unknown): string;
|
|
|
73
77
|
export declare class SuiteClient {
|
|
74
78
|
private readonly transport;
|
|
75
79
|
constructor(transport: SuiteTransport);
|
|
80
|
+
private call;
|
|
81
|
+
private send;
|
|
76
82
|
peers(): Promise<readonly SuitePeer[]>;
|
|
77
83
|
list(): Promise<readonly SuiteLink[]>;
|
|
78
84
|
get(id: string): Promise<SuiteLink>;
|
|
@@ -80,21 +86,14 @@ export declare class SuiteClient {
|
|
|
80
86
|
readonly peerApp: string;
|
|
81
87
|
readonly returnUrl: string;
|
|
82
88
|
readonly stateNonce: string;
|
|
83
|
-
}): Promise<
|
|
84
|
-
readonly requestId: string;
|
|
85
|
-
readonly authorizeUrl: string;
|
|
86
|
-
}>;
|
|
89
|
+
}): Promise<SuiteLinkStart>;
|
|
87
90
|
complete(requestId: string, code: string): Promise<SuiteLink>;
|
|
88
91
|
preview(client: string, hint?: string, hintDomain?: string): Promise<AuthorizationPreview>;
|
|
89
|
-
authorize(input: AuthorizationInput): Promise<
|
|
90
|
-
readonly redirectUrl: string;
|
|
91
|
-
}>;
|
|
92
|
+
authorize(input: AuthorizationInput): Promise<SuiteRedirect>;
|
|
92
93
|
deny(input: {
|
|
93
94
|
readonly client: string;
|
|
94
95
|
readonly state: string;
|
|
95
|
-
}): Promise<
|
|
96
|
-
readonly redirectUrl: string;
|
|
97
|
-
}>;
|
|
96
|
+
}): Promise<SuiteRedirect>;
|
|
98
97
|
update(id: string, input: {
|
|
99
98
|
readonly shareXp?: boolean;
|
|
100
99
|
readonly rewardMode?: RewardMode;
|
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,WAAW,GAAG,KAAK,CAAC;AACxD,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,UAAU,GAAG,iBAAiB,GAAG,UAAU,CAAC;AACrF,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,EAAE,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
|
|
|
1
|
+
import { isAuthorizationPreview, isSuiteDeliveries, isSuiteLink, isSuiteLinks, isSuiteLinkStart, isSuitePeers, isSuiteRedirect, parseSuiteResponse, } from './responses.js';
|
|
1
2
|
export class SuiteFlowError extends Error {
|
|
2
3
|
code;
|
|
3
4
|
constructor(code) {
|
|
@@ -35,20 +36,27 @@ export class SuiteClient {
|
|
|
35
36
|
constructor(transport) {
|
|
36
37
|
this.transport = transport;
|
|
37
38
|
}
|
|
39
|
+
async call(guard, method, path, body) {
|
|
40
|
+
const response = await this.transport.request(method, path, body);
|
|
41
|
+
return parseSuiteResponse(`${method} ${path.split('?')[0] ?? path}`, response, guard);
|
|
42
|
+
}
|
|
43
|
+
async send(method, path, body) {
|
|
44
|
+
await this.transport.request(method, path, body);
|
|
45
|
+
}
|
|
38
46
|
peers() {
|
|
39
|
-
return this.
|
|
47
|
+
return this.call(isSuitePeers, 'GET', '/suite/peers');
|
|
40
48
|
}
|
|
41
49
|
list() {
|
|
42
|
-
return this.
|
|
50
|
+
return this.call(isSuiteLinks, 'GET', '/suite/links');
|
|
43
51
|
}
|
|
44
52
|
get(id) {
|
|
45
|
-
return this.
|
|
53
|
+
return this.call(isSuiteLink, 'GET', linkPath(id));
|
|
46
54
|
}
|
|
47
55
|
start(input) {
|
|
48
|
-
return this.
|
|
56
|
+
return this.call(isSuiteLinkStart, 'POST', '/suite/links', input);
|
|
49
57
|
}
|
|
50
58
|
complete(requestId, code) {
|
|
51
|
-
return this.
|
|
59
|
+
return this.call(isSuiteLink, 'POST', `/suite/links/requests/${encodeURIComponent(requestId)}/complete`, { code });
|
|
52
60
|
}
|
|
53
61
|
preview(client, hint, hintDomain) {
|
|
54
62
|
const query = new URLSearchParams({ client });
|
|
@@ -56,31 +64,31 @@ export class SuiteClient {
|
|
|
56
64
|
query.set('hint', hint);
|
|
57
65
|
if (hintDomain !== undefined)
|
|
58
66
|
query.set('hint_domain', hintDomain);
|
|
59
|
-
return this.
|
|
67
|
+
return this.call(isAuthorizationPreview, 'GET', `/suite/authorizations/preview?${query.toString()}`);
|
|
60
68
|
}
|
|
61
69
|
authorize(input) {
|
|
62
|
-
return this.
|
|
70
|
+
return this.call(isSuiteRedirect, 'POST', '/suite/authorizations', input);
|
|
63
71
|
}
|
|
64
72
|
deny(input) {
|
|
65
|
-
return this.
|
|
73
|
+
return this.call(isSuiteRedirect, 'POST', '/suite/authorizations/deny', input);
|
|
66
74
|
}
|
|
67
75
|
update(id, input) {
|
|
68
|
-
return this.
|
|
76
|
+
return this.call(isSuiteLink, 'PATCH', linkPath(id), input);
|
|
69
77
|
}
|
|
70
78
|
disconnect(id) {
|
|
71
|
-
return this.
|
|
79
|
+
return this.send('DELETE', linkPath(id));
|
|
72
80
|
}
|
|
73
81
|
test(id) {
|
|
74
|
-
return this.
|
|
82
|
+
return this.send('POST', `${linkPath(id)}/test`);
|
|
75
83
|
}
|
|
76
84
|
reenable(id) {
|
|
77
|
-
return this.
|
|
85
|
+
return this.call(isSuiteLink, 'POST', `${linkPath(id)}/reenable`);
|
|
78
86
|
}
|
|
79
87
|
replay(id, since) {
|
|
80
|
-
return this.
|
|
88
|
+
return this.send('POST', `${linkPath(id)}/replay`, { since });
|
|
81
89
|
}
|
|
82
90
|
deliveries(id) {
|
|
83
|
-
return this.
|
|
91
|
+
return this.call(isSuiteDeliveries, 'GET', `${linkPath(id)}/deliveries`);
|
|
84
92
|
}
|
|
85
93
|
}
|
|
86
94
|
//# sourceMappingURL=api.js.map
|
package/dist/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,kBAAkB,GAGnB,MAAM,gBAAgB,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Q,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;IACnD,CAAC;IACM,QAAQ,CAAC,EAAU;QACxB,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,QAAQ,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC;IACpE,CAAC;IACM,MAAM,CAAC,EAAU,EAAE,KAAa;QACrC,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,QAAQ,CAAC,EAAE,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAChE,CAAC;IACM,UAAU,CAAC,EAAU;QAC1B,OAAO,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC;IAC3E,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AuthorizationPreview, SuiteDelivery, SuiteLink, SuitePeer } from './api.js';
|
|
2
|
+
export declare class SuiteResponseError extends Error {
|
|
3
|
+
readonly endpoint: string;
|
|
4
|
+
readonly code = "suite_unavailable";
|
|
5
|
+
constructor(endpoint: string);
|
|
6
|
+
}
|
|
7
|
+
type Guard<T> = (value: unknown) => value is T;
|
|
8
|
+
export interface SuiteLinkStart {
|
|
9
|
+
readonly requestId: string;
|
|
10
|
+
readonly authorizeUrl: string;
|
|
11
|
+
}
|
|
12
|
+
export interface SuiteRedirect {
|
|
13
|
+
readonly redirectUrl: string;
|
|
14
|
+
}
|
|
15
|
+
export declare const isSuiteLink: Guard<SuiteLink>;
|
|
16
|
+
export declare const isSuitePeer: Guard<SuitePeer>;
|
|
17
|
+
export declare const isAuthorizationPreview: Guard<AuthorizationPreview>;
|
|
18
|
+
export declare const isSuiteDelivery: Guard<SuiteDelivery>;
|
|
19
|
+
export declare const isSuiteLinkStart: Guard<SuiteLinkStart>;
|
|
20
|
+
export declare const isSuiteRedirect: Guard<SuiteRedirect>;
|
|
21
|
+
export declare const isSuitePeers: Guard<SuitePeer[]>;
|
|
22
|
+
export declare const isSuiteLinks: Guard<SuiteLink[]>;
|
|
23
|
+
export declare const isSuiteDeliveries: Guard<SuiteDelivery[]>;
|
|
24
|
+
export declare function parseSuiteResponse<T>(endpoint: string, value: unknown, guard: Guard<T>): T;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=responses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../src/responses.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,oBAAoB,EAGpB,aAAa,EACb,SAAS,EACT,SAAS,EACV,MAAM,UAAU,CAAC;AAElB,qBAAa,kBAAmB,SAAQ,KAAK;aAER,QAAQ,EAAE,MAAM;IADnD,SAAgB,IAAI,uBAAuB;gBACR,QAAQ,EAAE,MAAM;CAGpD;AAED,KAAK,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC;AAqC/C,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AACD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED,eAAO,MAAM,WAAW,kBAoBtB,CAAC;AACH,eAAO,MAAM,WAAW,kBAUtB,CAAC;AACH,eAAO,MAAM,sBAAsB,6BAOjC,CAAC;AACH,eAAO,MAAM,eAAe,sBAS1B,CAAC;AACH,eAAO,MAAM,gBAAgB,uBAG3B,CAAC;AACH,eAAO,MAAM,eAAe,sBAAmD,CAAC;AAEhF,eAAO,MAAM,YAAY,oBAAuB,CAAC;AACjD,eAAO,MAAM,YAAY,oBAAuB,CAAC;AACjD,eAAO,MAAM,iBAAiB,wBAA2B,CAAC;AAE1D,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAG1F"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { isBoolean, isNonNegativeSafeInteger, isRecord, isString, isStringArray, nullable, } from '@baukit/type-guards';
|
|
2
|
+
export class SuiteResponseError extends Error {
|
|
3
|
+
endpoint;
|
|
4
|
+
code = 'suite_unavailable';
|
|
5
|
+
constructor(endpoint) {
|
|
6
|
+
super(`suite response for ${endpoint} has an unexpected shape`);
|
|
7
|
+
this.endpoint = endpoint;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const REWARD_MODES = ['native', 'source_xp', 'off'];
|
|
11
|
+
const DELIVERY_HEALTHS = ['healthy', 'degraded', 'needs_attention', 'disabled'];
|
|
12
|
+
const LINK_ROLES = ['initiator', 'authorizer'];
|
|
13
|
+
const LINK_STATUSES = ['active', 'needs_attention', 'revoked'];
|
|
14
|
+
const DELIVERY_STATUSES = [
|
|
15
|
+
'pending',
|
|
16
|
+
'running',
|
|
17
|
+
'succeeded',
|
|
18
|
+
'failed',
|
|
19
|
+
'cancelled',
|
|
20
|
+
];
|
|
21
|
+
const isNullableString = nullable(isString);
|
|
22
|
+
function isOneOf(allowed) {
|
|
23
|
+
return (value) => typeof value === 'string' && allowed.includes(value);
|
|
24
|
+
}
|
|
25
|
+
const isRewardMode = isOneOf(REWARD_MODES);
|
|
26
|
+
const isDeliveryHealth = isOneOf(DELIVERY_HEALTHS);
|
|
27
|
+
const isLinkRole = isOneOf(LINK_ROLES);
|
|
28
|
+
const isLinkStatus = isOneOf(LINK_STATUSES);
|
|
29
|
+
const isDeliveryStatus = isOneOf(DELIVERY_STATUSES);
|
|
30
|
+
const isRewardModeArray = arrayOf(isRewardMode);
|
|
31
|
+
function arrayOf(guard) {
|
|
32
|
+
return (value) => Array.isArray(value) && value.every(guard);
|
|
33
|
+
}
|
|
34
|
+
function shaped(shape) {
|
|
35
|
+
const fields = Object.entries(shape);
|
|
36
|
+
return (value) => isRecord(value) && fields.every(([key, guard]) => guard(value[key]));
|
|
37
|
+
}
|
|
38
|
+
export const isSuiteLink = shaped({
|
|
39
|
+
id: isString,
|
|
40
|
+
peerApp: isString,
|
|
41
|
+
role: isLinkRole,
|
|
42
|
+
remoteLinkId: isString,
|
|
43
|
+
remoteDisplayName: isNullableString,
|
|
44
|
+
status: isLinkStatus,
|
|
45
|
+
sends: isStringArray,
|
|
46
|
+
receives: isStringArray,
|
|
47
|
+
shareXp: isBoolean,
|
|
48
|
+
rewardMode: isRewardMode,
|
|
49
|
+
deliveryHealth: isDeliveryHealth,
|
|
50
|
+
consecutiveFailures: isNonNegativeSafeInteger,
|
|
51
|
+
lastDeliveryAt: isNullableString,
|
|
52
|
+
lastFailureAt: isNullableString,
|
|
53
|
+
lastFailureCode: isNullableString,
|
|
54
|
+
lastReceivedAt: isNullableString,
|
|
55
|
+
replayEarliest: isString,
|
|
56
|
+
createdAt: isString,
|
|
57
|
+
updatedAt: isString,
|
|
58
|
+
});
|
|
59
|
+
export const isSuitePeer = shaped({
|
|
60
|
+
id: isString,
|
|
61
|
+
displayName: isString,
|
|
62
|
+
scheme: isString,
|
|
63
|
+
webUrl: isString,
|
|
64
|
+
shareXpAvailable: isBoolean,
|
|
65
|
+
sends: isStringArray,
|
|
66
|
+
receives: isStringArray,
|
|
67
|
+
rewardModes: isRewardModeArray,
|
|
68
|
+
link: isNullableString,
|
|
69
|
+
});
|
|
70
|
+
export const isAuthorizationPreview = shaped({
|
|
71
|
+
peer: isString,
|
|
72
|
+
authorizerSends: isStringArray,
|
|
73
|
+
initiatorSends: isStringArray,
|
|
74
|
+
existingLink: isBoolean,
|
|
75
|
+
autoApprove: isBoolean,
|
|
76
|
+
hintMismatch: isBoolean,
|
|
77
|
+
});
|
|
78
|
+
export const isSuiteDelivery = shaped({
|
|
79
|
+
jobId: isString,
|
|
80
|
+
linkId: isString,
|
|
81
|
+
eventType: isNullableString,
|
|
82
|
+
status: isDeliveryStatus,
|
|
83
|
+
attemptCount: isNonNegativeSafeInteger,
|
|
84
|
+
lastFailureCode: isNullableString,
|
|
85
|
+
createdAt: isString,
|
|
86
|
+
updatedAt: isString,
|
|
87
|
+
});
|
|
88
|
+
export const isSuiteLinkStart = shaped({
|
|
89
|
+
requestId: isString,
|
|
90
|
+
authorizeUrl: isString,
|
|
91
|
+
});
|
|
92
|
+
export const isSuiteRedirect = shaped({ redirectUrl: isString });
|
|
93
|
+
export const isSuitePeers = arrayOf(isSuitePeer);
|
|
94
|
+
export const isSuiteLinks = arrayOf(isSuiteLink);
|
|
95
|
+
export const isSuiteDeliveries = arrayOf(isSuiteDelivery);
|
|
96
|
+
export function parseSuiteResponse(endpoint, value, guard) {
|
|
97
|
+
if (!guard(value))
|
|
98
|
+
throw new SuiteResponseError(endpoint);
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=responses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responses.js","sourceRoot":"","sources":["../src/responses.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,wBAAwB,EACxB,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,QAAQ,GACT,MAAM,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"name": "@baukit/suite-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "Headless suite linking, authorization state and connected app clients.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Patrick Koss",
|
|
@@ -69,11 +69,11 @@
|
|
|
69
69
|
"vitest": "5.0.5"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
|
-
"@baukit/integrations-client": "^0.
|
|
73
|
-
"@baukit/localization-core": "^0.
|
|
72
|
+
"@baukit/integrations-client": "^0.20.0",
|
|
73
|
+
"@baukit/localization-core": "^0.20.0"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@baukit/type-guards": "^0.
|
|
76
|
+
"@baukit/type-guards": "^0.20.0",
|
|
77
77
|
"@noble/curves": "1.9.7"
|
|
78
78
|
}
|
|
79
79
|
}
|
package/src/api.ts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isAuthorizationPreview,
|
|
3
|
+
isSuiteDeliveries,
|
|
4
|
+
isSuiteLink,
|
|
5
|
+
isSuiteLinks,
|
|
6
|
+
isSuiteLinkStart,
|
|
7
|
+
isSuitePeers,
|
|
8
|
+
isSuiteRedirect,
|
|
9
|
+
parseSuiteResponse,
|
|
10
|
+
type SuiteLinkStart,
|
|
11
|
+
type SuiteRedirect,
|
|
12
|
+
} from './responses.js';
|
|
1
13
|
export type RewardMode = 'native' | 'source_xp' | 'off';
|
|
2
14
|
export type DeliveryHealth = 'healthy' | 'degraded' | 'needs_attention' | 'disabled';
|
|
3
15
|
export interface SuiteLink {
|
|
@@ -56,9 +68,16 @@ export interface SuiteDelivery {
|
|
|
56
68
|
readonly createdAt: string;
|
|
57
69
|
readonly updatedAt: string;
|
|
58
70
|
}
|
|
59
|
-
/**
|
|
71
|
+
/**
|
|
72
|
+
* Supply the product's authenticated, JSON-decoding HTTP transport. Return the decoded body
|
|
73
|
+
* untyped; SuiteClient validates every response and throws SuiteResponseError on a mismatch.
|
|
74
|
+
*/
|
|
60
75
|
export interface SuiteTransport {
|
|
61
|
-
request
|
|
76
|
+
request(
|
|
77
|
+
method: 'GET' | 'POST' | 'PATCH' | 'DELETE',
|
|
78
|
+
path: string,
|
|
79
|
+
body?: unknown,
|
|
80
|
+
): Promise<unknown>;
|
|
62
81
|
}
|
|
63
82
|
export class SuiteFlowError extends Error {
|
|
64
83
|
public constructor(public readonly code: string) {
|
|
@@ -105,24 +124,37 @@ export function suiteErrorCode(error: unknown): string {
|
|
|
105
124
|
const linkPath = (id: string) => `/suite/links/${encodeURIComponent(id)}`;
|
|
106
125
|
export class SuiteClient {
|
|
107
126
|
public constructor(private readonly transport: SuiteTransport) {}
|
|
127
|
+
private async call<T>(
|
|
128
|
+
guard: (value: unknown) => value is T,
|
|
129
|
+
method: 'GET' | 'POST' | 'PATCH' | 'DELETE',
|
|
130
|
+
path: string,
|
|
131
|
+
body?: unknown,
|
|
132
|
+
): Promise<T> {
|
|
133
|
+
const response = await this.transport.request(method, path, body);
|
|
134
|
+
return parseSuiteResponse(`${method} ${path.split('?')[0] ?? path}`, response, guard);
|
|
135
|
+
}
|
|
136
|
+
private async send(method: 'POST' | 'DELETE', path: string, body?: unknown): Promise<void> {
|
|
137
|
+
await this.transport.request(method, path, body);
|
|
138
|
+
}
|
|
108
139
|
public peers(): Promise<readonly SuitePeer[]> {
|
|
109
|
-
return this.
|
|
140
|
+
return this.call(isSuitePeers, 'GET', '/suite/peers');
|
|
110
141
|
}
|
|
111
142
|
public list(): Promise<readonly SuiteLink[]> {
|
|
112
|
-
return this.
|
|
143
|
+
return this.call(isSuiteLinks, 'GET', '/suite/links');
|
|
113
144
|
}
|
|
114
145
|
public get(id: string): Promise<SuiteLink> {
|
|
115
|
-
return this.
|
|
146
|
+
return this.call(isSuiteLink, 'GET', linkPath(id));
|
|
116
147
|
}
|
|
117
148
|
public start(input: {
|
|
118
149
|
readonly peerApp: string;
|
|
119
150
|
readonly returnUrl: string;
|
|
120
151
|
readonly stateNonce: string;
|
|
121
|
-
}): Promise<
|
|
122
|
-
return this.
|
|
152
|
+
}): Promise<SuiteLinkStart> {
|
|
153
|
+
return this.call(isSuiteLinkStart, 'POST', '/suite/links', input);
|
|
123
154
|
}
|
|
124
155
|
public complete(requestId: string, code: string): Promise<SuiteLink> {
|
|
125
|
-
return this.
|
|
156
|
+
return this.call(
|
|
157
|
+
isSuiteLink,
|
|
126
158
|
'POST',
|
|
127
159
|
`/suite/links/requests/${encodeURIComponent(requestId)}/complete`,
|
|
128
160
|
{ code },
|
|
@@ -136,36 +168,37 @@ export class SuiteClient {
|
|
|
136
168
|
const query = new URLSearchParams({ client });
|
|
137
169
|
if (hint !== undefined) query.set('hint', hint);
|
|
138
170
|
if (hintDomain !== undefined) query.set('hint_domain', hintDomain);
|
|
139
|
-
return this.
|
|
171
|
+
return this.call(
|
|
172
|
+
isAuthorizationPreview,
|
|
173
|
+
'GET',
|
|
174
|
+
`/suite/authorizations/preview?${query.toString()}`,
|
|
175
|
+
);
|
|
140
176
|
}
|
|
141
|
-
public authorize(input: AuthorizationInput): Promise<
|
|
142
|
-
return this.
|
|
177
|
+
public authorize(input: AuthorizationInput): Promise<SuiteRedirect> {
|
|
178
|
+
return this.call(isSuiteRedirect, 'POST', '/suite/authorizations', input);
|
|
143
179
|
}
|
|
144
|
-
public deny(input: {
|
|
145
|
-
|
|
146
|
-
readonly state: string;
|
|
147
|
-
}): Promise<{ readonly redirectUrl: string }> {
|
|
148
|
-
return this.transport.request('POST', '/suite/authorizations/deny', input);
|
|
180
|
+
public deny(input: { readonly client: string; readonly state: string }): Promise<SuiteRedirect> {
|
|
181
|
+
return this.call(isSuiteRedirect, 'POST', '/suite/authorizations/deny', input);
|
|
149
182
|
}
|
|
150
183
|
public update(
|
|
151
184
|
id: string,
|
|
152
185
|
input: { readonly shareXp?: boolean; readonly rewardMode?: RewardMode },
|
|
153
186
|
): Promise<SuiteLink> {
|
|
154
|
-
return this.
|
|
187
|
+
return this.call(isSuiteLink, 'PATCH', linkPath(id), input);
|
|
155
188
|
}
|
|
156
189
|
public disconnect(id: string): Promise<void> {
|
|
157
|
-
return this.
|
|
190
|
+
return this.send('DELETE', linkPath(id));
|
|
158
191
|
}
|
|
159
192
|
public test(id: string): Promise<void> {
|
|
160
|
-
return this.
|
|
193
|
+
return this.send('POST', `${linkPath(id)}/test`);
|
|
161
194
|
}
|
|
162
195
|
public reenable(id: string): Promise<SuiteLink> {
|
|
163
|
-
return this.
|
|
196
|
+
return this.call(isSuiteLink, 'POST', `${linkPath(id)}/reenable`);
|
|
164
197
|
}
|
|
165
198
|
public replay(id: string, since: string): Promise<void> {
|
|
166
|
-
return this.
|
|
199
|
+
return this.send('POST', `${linkPath(id)}/replay`, { since });
|
|
167
200
|
}
|
|
168
201
|
public deliveries(id: string): Promise<readonly SuiteDelivery[]> {
|
|
169
|
-
return this.
|
|
202
|
+
return this.call(isSuiteDeliveries, 'GET', `${linkPath(id)}/deliveries`);
|
|
170
203
|
}
|
|
171
204
|
}
|
package/src/client.test.ts
CHANGED
|
@@ -57,30 +57,20 @@ const input = {
|
|
|
57
57
|
hint: 'hint',
|
|
58
58
|
hintDomain: 'shared',
|
|
59
59
|
};
|
|
60
|
+
function respond(method: string, path: string): unknown {
|
|
61
|
+
if (path.includes('/preview?')) return preview;
|
|
62
|
+
if (path === '/suite/links' && method === 'POST')
|
|
63
|
+
return { requestId: 'request', authorizeUrl: 'https://beta.example/suite/authorize' };
|
|
64
|
+
if (path === '/suite/peers' || path.endsWith('/deliveries') || path === '/suite/links') return [];
|
|
65
|
+
if (path.startsWith('/suite/authorizations'))
|
|
66
|
+
return { redirectUrl: 'https://alpha.example/suite/links/callback' };
|
|
67
|
+
return link;
|
|
68
|
+
}
|
|
60
69
|
function apiFixture() {
|
|
61
70
|
const request = vi.fn<(method: string, path: string, body?: unknown) => Promise<unknown>>(
|
|
62
|
-
(
|
|
63
|
-
if (path.includes('/preview?')) return Promise.resolve(preview);
|
|
64
|
-
if (path === '/suite/links' && _method === 'POST')
|
|
65
|
-
return Promise.resolve({
|
|
66
|
-
requestId: 'request',
|
|
67
|
-
authorizeUrl: 'https://beta.example/suite/authorize',
|
|
68
|
-
});
|
|
69
|
-
if (path === '/suite/peers' || (path === '/suite/links' && _method === 'GET'))
|
|
70
|
-
return Promise.resolve([]);
|
|
71
|
-
if (path.endsWith('/complete')) return Promise.resolve(link);
|
|
72
|
-
return Promise.resolve({ redirectUrl: 'https://alpha.example/suite/links/callback' });
|
|
73
|
-
},
|
|
71
|
+
(method, path) => Promise.resolve(respond(method, path)),
|
|
74
72
|
);
|
|
75
|
-
const transport: SuiteTransport = {
|
|
76
|
-
async request<T>(
|
|
77
|
-
method: 'GET' | 'POST' | 'PATCH' | 'DELETE',
|
|
78
|
-
path: string,
|
|
79
|
-
body?: unknown,
|
|
80
|
-
): Promise<T> {
|
|
81
|
-
return (await request(method, path, body)) as T;
|
|
82
|
-
},
|
|
83
|
-
};
|
|
73
|
+
const transport: SuiteTransport = { request };
|
|
84
74
|
return { client: new SuiteClient(transport), request };
|
|
85
75
|
}
|
|
86
76
|
function sessionFixture(platform: 'web' | 'native' = 'native') {
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
SuiteClient,
|
|
4
|
+
SuiteResponseError,
|
|
5
|
+
suiteErrorCode,
|
|
6
|
+
type AuthorizationInput,
|
|
7
|
+
type SuiteDelivery,
|
|
8
|
+
type SuiteLink,
|
|
9
|
+
type SuiteTransport,
|
|
10
|
+
} from './index.js';
|
|
11
|
+
|
|
12
|
+
const link: SuiteLink = {
|
|
13
|
+
id: 'link',
|
|
14
|
+
peerApp: 'beta',
|
|
15
|
+
role: 'initiator',
|
|
16
|
+
remoteLinkId: 'remote',
|
|
17
|
+
remoteDisplayName: 'User',
|
|
18
|
+
status: 'active',
|
|
19
|
+
sends: [],
|
|
20
|
+
receives: [],
|
|
21
|
+
shareXp: true,
|
|
22
|
+
rewardMode: 'native',
|
|
23
|
+
deliveryHealth: 'healthy',
|
|
24
|
+
consecutiveFailures: 0,
|
|
25
|
+
lastDeliveryAt: null,
|
|
26
|
+
lastFailureAt: null,
|
|
27
|
+
lastFailureCode: null,
|
|
28
|
+
lastReceivedAt: null,
|
|
29
|
+
replayEarliest: '2025-10-07',
|
|
30
|
+
createdAt: '2026-10-07T00:00:00Z',
|
|
31
|
+
updatedAt: '2026-10-07T00:00:00Z',
|
|
32
|
+
};
|
|
33
|
+
const input: AuthorizationInput = { client: 'alpha', state: 'state', codeChallenge: 'challenge' };
|
|
34
|
+
function apiFixture() {
|
|
35
|
+
const request = vi.fn<(method: string, path: string, body?: unknown) => Promise<unknown>>(() =>
|
|
36
|
+
Promise.resolve(link),
|
|
37
|
+
);
|
|
38
|
+
const transport: SuiteTransport = { request };
|
|
39
|
+
return { client: new SuiteClient(transport), request };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe('response validation', () => {
|
|
43
|
+
const calls: readonly (readonly [string, (client: SuiteClient) => Promise<unknown>])[] = [
|
|
44
|
+
['peers', (c) => c.peers()],
|
|
45
|
+
['list', (c) => c.list()],
|
|
46
|
+
['get', (c) => c.get('id')],
|
|
47
|
+
['start', (c) => c.start({ peerApp: 'beta', returnUrl: 'r', stateNonce: 'n' })],
|
|
48
|
+
['complete', (c) => c.complete('request', 'code')],
|
|
49
|
+
['preview', (c) => c.preview('alpha')],
|
|
50
|
+
['authorize', (c) => c.authorize(input)],
|
|
51
|
+
['deny', (c) => c.deny({ client: 'alpha', state: 'state' })],
|
|
52
|
+
['update', (c) => c.update('id', { shareXp: false })],
|
|
53
|
+
['reenable', (c) => c.reenable('id')],
|
|
54
|
+
['deliveries', (c) => c.deliveries('id')],
|
|
55
|
+
];
|
|
56
|
+
it.each(calls)('rejects a malformed %s response with SuiteResponseError', async (_name, call) => {
|
|
57
|
+
const { client, request } = apiFixture();
|
|
58
|
+
request.mockResolvedValueOnce({ unexpected: true });
|
|
59
|
+
const error: unknown = await call(client).catch((caught: unknown) => caught);
|
|
60
|
+
expect(error).toBeInstanceOf(SuiteResponseError);
|
|
61
|
+
expect(suiteErrorCode(error)).toBe('suite_unavailable');
|
|
62
|
+
});
|
|
63
|
+
it('rejects links and deliveries with invalid fields inside arrays', async () => {
|
|
64
|
+
const { client, request } = apiFixture();
|
|
65
|
+
request.mockResolvedValueOnce([{ ...link, status: 'bogus' }]);
|
|
66
|
+
await expect(client.list()).rejects.toBeInstanceOf(SuiteResponseError);
|
|
67
|
+
request.mockResolvedValueOnce([{ jobId: 'job' }]);
|
|
68
|
+
await expect(client.deliveries('id')).rejects.toBeInstanceOf(SuiteResponseError);
|
|
69
|
+
request.mockResolvedValueOnce([{ id: 'peer' }]);
|
|
70
|
+
await expect(client.peers()).rejects.toBeInstanceOf(SuiteResponseError);
|
|
71
|
+
});
|
|
72
|
+
it('accepts a valid delivery list and ignores bodies of void endpoints', async () => {
|
|
73
|
+
const { client, request } = apiFixture();
|
|
74
|
+
const delivery: SuiteDelivery = {
|
|
75
|
+
jobId: 'job',
|
|
76
|
+
linkId: 'link',
|
|
77
|
+
eventType: null,
|
|
78
|
+
status: 'pending',
|
|
79
|
+
attemptCount: 0,
|
|
80
|
+
lastFailureCode: null,
|
|
81
|
+
createdAt: '2026-10-07T00:00:00Z',
|
|
82
|
+
updatedAt: '2026-10-07T00:00:00Z',
|
|
83
|
+
};
|
|
84
|
+
request.mockResolvedValueOnce([delivery]);
|
|
85
|
+
expect(await client.deliveries('id')).toEqual([delivery]);
|
|
86
|
+
request.mockResolvedValueOnce(undefined);
|
|
87
|
+
await expect(client.disconnect('id')).resolves.toBeUndefined();
|
|
88
|
+
});
|
|
89
|
+
});
|
package/src/responses.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isBoolean,
|
|
3
|
+
isNonNegativeSafeInteger,
|
|
4
|
+
isRecord,
|
|
5
|
+
isString,
|
|
6
|
+
isStringArray,
|
|
7
|
+
nullable,
|
|
8
|
+
} from '@baukit/type-guards';
|
|
9
|
+
import type {
|
|
10
|
+
AuthorizationPreview,
|
|
11
|
+
DeliveryHealth,
|
|
12
|
+
RewardMode,
|
|
13
|
+
SuiteDelivery,
|
|
14
|
+
SuiteLink,
|
|
15
|
+
SuitePeer,
|
|
16
|
+
} from './api.js';
|
|
17
|
+
|
|
18
|
+
export class SuiteResponseError extends Error {
|
|
19
|
+
public readonly code = 'suite_unavailable';
|
|
20
|
+
public constructor(public readonly endpoint: string) {
|
|
21
|
+
super(`suite response for ${endpoint} has an unexpected shape`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type Guard<T> = (value: unknown) => value is T;
|
|
26
|
+
|
|
27
|
+
const REWARD_MODES: readonly string[] = ['native', 'source_xp', 'off'];
|
|
28
|
+
const DELIVERY_HEALTHS: readonly string[] = ['healthy', 'degraded', 'needs_attention', 'disabled'];
|
|
29
|
+
const LINK_ROLES: readonly string[] = ['initiator', 'authorizer'];
|
|
30
|
+
const LINK_STATUSES: readonly string[] = ['active', 'needs_attention', 'revoked'];
|
|
31
|
+
const DELIVERY_STATUSES: readonly string[] = [
|
|
32
|
+
'pending',
|
|
33
|
+
'running',
|
|
34
|
+
'succeeded',
|
|
35
|
+
'failed',
|
|
36
|
+
'cancelled',
|
|
37
|
+
];
|
|
38
|
+
const isNullableString = nullable(isString);
|
|
39
|
+
|
|
40
|
+
function isOneOf<T extends string>(allowed: readonly string[]): Guard<T> {
|
|
41
|
+
return (value): value is T => typeof value === 'string' && allowed.includes(value);
|
|
42
|
+
}
|
|
43
|
+
const isRewardMode = isOneOf<RewardMode>(REWARD_MODES);
|
|
44
|
+
const isDeliveryHealth = isOneOf<DeliveryHealth>(DELIVERY_HEALTHS);
|
|
45
|
+
const isLinkRole = isOneOf<SuiteLink['role']>(LINK_ROLES);
|
|
46
|
+
const isLinkStatus = isOneOf<SuiteLink['status']>(LINK_STATUSES);
|
|
47
|
+
const isDeliveryStatus = isOneOf<SuiteDelivery['status']>(DELIVERY_STATUSES);
|
|
48
|
+
const isRewardModeArray = arrayOf(isRewardMode);
|
|
49
|
+
|
|
50
|
+
function arrayOf<T>(guard: Guard<T>): Guard<T[]> {
|
|
51
|
+
return (value): value is T[] => Array.isArray(value) && value.every(guard);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
type Shape<T> = { readonly [K in keyof T]-?: Guard<T[K]> };
|
|
55
|
+
|
|
56
|
+
function shaped<T extends object>(shape: Shape<T>): Guard<T> {
|
|
57
|
+
const fields = Object.entries<Guard<unknown>>(shape);
|
|
58
|
+
return (value): value is T =>
|
|
59
|
+
isRecord(value) && fields.every(([key, guard]) => guard(value[key]));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface SuiteLinkStart {
|
|
63
|
+
readonly requestId: string;
|
|
64
|
+
readonly authorizeUrl: string;
|
|
65
|
+
}
|
|
66
|
+
export interface SuiteRedirect {
|
|
67
|
+
readonly redirectUrl: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export const isSuiteLink = shaped<SuiteLink>({
|
|
71
|
+
id: isString,
|
|
72
|
+
peerApp: isString,
|
|
73
|
+
role: isLinkRole,
|
|
74
|
+
remoteLinkId: isString,
|
|
75
|
+
remoteDisplayName: isNullableString,
|
|
76
|
+
status: isLinkStatus,
|
|
77
|
+
sends: isStringArray,
|
|
78
|
+
receives: isStringArray,
|
|
79
|
+
shareXp: isBoolean,
|
|
80
|
+
rewardMode: isRewardMode,
|
|
81
|
+
deliveryHealth: isDeliveryHealth,
|
|
82
|
+
consecutiveFailures: isNonNegativeSafeInteger,
|
|
83
|
+
lastDeliveryAt: isNullableString,
|
|
84
|
+
lastFailureAt: isNullableString,
|
|
85
|
+
lastFailureCode: isNullableString,
|
|
86
|
+
lastReceivedAt: isNullableString,
|
|
87
|
+
replayEarliest: isString,
|
|
88
|
+
createdAt: isString,
|
|
89
|
+
updatedAt: isString,
|
|
90
|
+
});
|
|
91
|
+
export const isSuitePeer = shaped<SuitePeer>({
|
|
92
|
+
id: isString,
|
|
93
|
+
displayName: isString,
|
|
94
|
+
scheme: isString,
|
|
95
|
+
webUrl: isString,
|
|
96
|
+
shareXpAvailable: isBoolean,
|
|
97
|
+
sends: isStringArray,
|
|
98
|
+
receives: isStringArray,
|
|
99
|
+
rewardModes: isRewardModeArray,
|
|
100
|
+
link: isNullableString,
|
|
101
|
+
});
|
|
102
|
+
export const isAuthorizationPreview = shaped<AuthorizationPreview>({
|
|
103
|
+
peer: isString,
|
|
104
|
+
authorizerSends: isStringArray,
|
|
105
|
+
initiatorSends: isStringArray,
|
|
106
|
+
existingLink: isBoolean,
|
|
107
|
+
autoApprove: isBoolean,
|
|
108
|
+
hintMismatch: isBoolean,
|
|
109
|
+
});
|
|
110
|
+
export const isSuiteDelivery = shaped<SuiteDelivery>({
|
|
111
|
+
jobId: isString,
|
|
112
|
+
linkId: isString,
|
|
113
|
+
eventType: isNullableString,
|
|
114
|
+
status: isDeliveryStatus,
|
|
115
|
+
attemptCount: isNonNegativeSafeInteger,
|
|
116
|
+
lastFailureCode: isNullableString,
|
|
117
|
+
createdAt: isString,
|
|
118
|
+
updatedAt: isString,
|
|
119
|
+
});
|
|
120
|
+
export const isSuiteLinkStart = shaped<SuiteLinkStart>({
|
|
121
|
+
requestId: isString,
|
|
122
|
+
authorizeUrl: isString,
|
|
123
|
+
});
|
|
124
|
+
export const isSuiteRedirect = shaped<SuiteRedirect>({ redirectUrl: isString });
|
|
125
|
+
|
|
126
|
+
export const isSuitePeers = arrayOf(isSuitePeer);
|
|
127
|
+
export const isSuiteLinks = arrayOf(isSuiteLink);
|
|
128
|
+
export const isSuiteDeliveries = arrayOf(isSuiteDelivery);
|
|
129
|
+
|
|
130
|
+
export function parseSuiteResponse<T>(endpoint: string, value: unknown, guard: Guard<T>): T {
|
|
131
|
+
if (!guard(value)) throw new SuiteResponseError(endpoint);
|
|
132
|
+
return value;
|
|
133
|
+
}
|