@clearly-hub/node 0.0.0-stage → 0.1.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/LICENSE +14 -0
- package/README.md +125 -2
- package/dist/index.cjs +668 -0
- package/dist/index.d.cts +168 -0
- package/dist/index.d.ts +168 -0
- package/dist/index.js +631 -0
- package/package.json +39 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import * as http from 'http';
|
|
2
|
+
|
|
3
|
+
declare const SCREEN_ACTIONS: readonly ["SELECT_SUBSCRIPTION", "DATA_PICKER", "REGISTER_RESOURCE", "SELECT_HUB"];
|
|
4
|
+
type ScreenAction = (typeof SCREEN_ACTIONS)[number];
|
|
5
|
+
declare function isScreenAction(value: unknown): value is ScreenAction;
|
|
6
|
+
type ScreenDisplay = 'redirect' | 'popup';
|
|
7
|
+
interface ScreenData {
|
|
8
|
+
REGISTER_RESOURCE: {
|
|
9
|
+
url: string;
|
|
10
|
+
format: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
interface HubRef {
|
|
14
|
+
_id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
}
|
|
17
|
+
interface PickedResource {
|
|
18
|
+
datasetTitle: string;
|
|
19
|
+
resourceName: string;
|
|
20
|
+
format: string;
|
|
21
|
+
accessibility: 'OPEN' | 'PROTECTED' | 'PAID';
|
|
22
|
+
url: string;
|
|
23
|
+
requiresToken: boolean;
|
|
24
|
+
hasAccess: boolean;
|
|
25
|
+
}
|
|
26
|
+
interface ScreenAnswers {
|
|
27
|
+
SELECT_SUBSCRIPTION: {
|
|
28
|
+
subscription: {
|
|
29
|
+
_id: string;
|
|
30
|
+
status: 'ACTIVE' | 'PENDING';
|
|
31
|
+
externalReference: string;
|
|
32
|
+
};
|
|
33
|
+
subscribedHub: HubRef & {
|
|
34
|
+
role?: 'ADMIN' | 'MEMBER';
|
|
35
|
+
};
|
|
36
|
+
user?: {
|
|
37
|
+
_id: string;
|
|
38
|
+
email: string;
|
|
39
|
+
};
|
|
40
|
+
hasMultipleSubscriptions?: boolean;
|
|
41
|
+
};
|
|
42
|
+
DATA_PICKER: {
|
|
43
|
+
activeHub: HubRef;
|
|
44
|
+
resources: PickedResource[];
|
|
45
|
+
};
|
|
46
|
+
REGISTER_RESOURCE: {
|
|
47
|
+
activeHub: string;
|
|
48
|
+
dataset: {
|
|
49
|
+
datasetId: string;
|
|
50
|
+
datasetTitle?: string;
|
|
51
|
+
};
|
|
52
|
+
resource: {
|
|
53
|
+
resourceId: string;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
SELECT_HUB: {
|
|
57
|
+
hub: HubRef;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
type ScreenResult<A extends ScreenAction = ScreenAction> = {
|
|
61
|
+
action: A;
|
|
62
|
+
result: 'SUCCESS';
|
|
63
|
+
answer: ScreenAnswers[A];
|
|
64
|
+
} | {
|
|
65
|
+
action: A;
|
|
66
|
+
result: 'CANCELLED' | 'FAILURE';
|
|
67
|
+
answer?: undefined;
|
|
68
|
+
error?: string;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
interface SessionUser {
|
|
72
|
+
sub: string;
|
|
73
|
+
email: string;
|
|
74
|
+
name?: string;
|
|
75
|
+
appUserId?: string;
|
|
76
|
+
}
|
|
77
|
+
interface HubSubscription {
|
|
78
|
+
subscriptionId: string;
|
|
79
|
+
status: 'ACTIVE' | 'PENDING';
|
|
80
|
+
planName: string;
|
|
81
|
+
planId?: string;
|
|
82
|
+
}
|
|
83
|
+
type Session = {
|
|
84
|
+
signedIn: false;
|
|
85
|
+
} | {
|
|
86
|
+
signedIn: true;
|
|
87
|
+
user: SessionUser;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
declare const DEFAULT_BASE_PATH = "/clearly-hub";
|
|
91
|
+
declare const DEFAULT_HUB_URL = "https://hub.clearly.app";
|
|
92
|
+
declare const DEFAULT_AUTH_URL = "https://auth.clearly.app";
|
|
93
|
+
declare const DEFAULT_ISSUER = "https://cognito-idp.eu-central-1.amazonaws.com/eu-central-1_1fM1Zd9mJ";
|
|
94
|
+
declare const ROUTES: {
|
|
95
|
+
readonly signIn: "/sign-in";
|
|
96
|
+
readonly callback: "/callback";
|
|
97
|
+
readonly signOut: "/sign-out";
|
|
98
|
+
readonly session: "/session";
|
|
99
|
+
readonly open: "/open";
|
|
100
|
+
readonly answer: "/answer";
|
|
101
|
+
readonly result: "/result";
|
|
102
|
+
};
|
|
103
|
+
declare const ANSWER_CHANNEL = "clearly-hub-answers";
|
|
104
|
+
interface AnswerMessage {
|
|
105
|
+
ref: string;
|
|
106
|
+
result: ScreenResult;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
interface SignedInPerson {
|
|
110
|
+
sub: string;
|
|
111
|
+
email: string;
|
|
112
|
+
name?: string;
|
|
113
|
+
}
|
|
114
|
+
interface ClearlyHubOptions {
|
|
115
|
+
clientId: string;
|
|
116
|
+
m2mClientId?: string;
|
|
117
|
+
m2mClientSecret?: string;
|
|
118
|
+
appUrl: string;
|
|
119
|
+
secret: string;
|
|
120
|
+
basePath?: string;
|
|
121
|
+
hubUrl?: string;
|
|
122
|
+
urls?: Partial<ClearlyHubUrls>;
|
|
123
|
+
signedOutUrl?: string;
|
|
124
|
+
onSignIn?: (person: SignedInPerson) => Promise<string | void> | string | void;
|
|
125
|
+
onAnswer?: (result: ScreenResult, context: {
|
|
126
|
+
user?: SessionUser;
|
|
127
|
+
}) => Promise<void> | void;
|
|
128
|
+
fetch?: typeof fetch;
|
|
129
|
+
}
|
|
130
|
+
interface ClearlyHubUrls {
|
|
131
|
+
screens: string;
|
|
132
|
+
api: string;
|
|
133
|
+
usage: string;
|
|
134
|
+
publicKey: string;
|
|
135
|
+
auth: string;
|
|
136
|
+
issuer: string;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
interface AppSubscription extends HubSubscription {
|
|
140
|
+
hubId: string;
|
|
141
|
+
hubName: string;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
type CookieSource = Request | {
|
|
145
|
+
headers: Record<string, string | string[] | undefined>;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
declare function clearlyHub(options: ClearlyHubOptions): {
|
|
149
|
+
handler: (request: Request) => Promise<Response>;
|
|
150
|
+
express: () => (req: http.IncomingMessage & {
|
|
151
|
+
originalUrl?: string;
|
|
152
|
+
}, res: http.ServerResponse, next?: (error?: unknown) => void) => Promise<void>;
|
|
153
|
+
getUser(request: CookieSource): Promise<SessionUser | null>;
|
|
154
|
+
getUserToken: (request: CookieSource) => Promise<string | undefined>;
|
|
155
|
+
fetchAsUser(request: CookieSource, url: string, init?: RequestInit): Promise<Response>;
|
|
156
|
+
getAppToken: () => Promise<string>;
|
|
157
|
+
getSubscriptions: () => Promise<AppSubscription[]>;
|
|
158
|
+
getSubscription(hubId: string): Promise<AppSubscription | null>;
|
|
159
|
+
reportUsage({ request, hubId, quantity, }: {
|
|
160
|
+
request: CookieSource;
|
|
161
|
+
hubId: string;
|
|
162
|
+
quantity?: number;
|
|
163
|
+
}): Promise<void>;
|
|
164
|
+
};
|
|
165
|
+
type ClearlyHub = ReturnType<typeof clearlyHub>;
|
|
166
|
+
|
|
167
|
+
export { ANSWER_CHANNEL, DEFAULT_AUTH_URL, DEFAULT_BASE_PATH, DEFAULT_HUB_URL, DEFAULT_ISSUER, ROUTES, SCREEN_ACTIONS, clearlyHub, isScreenAction };
|
|
168
|
+
export type { AnswerMessage, AppSubscription, ClearlyHub, ClearlyHubOptions, ClearlyHubUrls, CookieSource, HubRef, HubSubscription, PickedResource, ScreenAction, ScreenAnswers, ScreenData, ScreenDisplay, ScreenResult, Session, SessionUser, SignedInPerson };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import * as http from 'http';
|
|
2
|
+
|
|
3
|
+
declare const SCREEN_ACTIONS: readonly ["SELECT_SUBSCRIPTION", "DATA_PICKER", "REGISTER_RESOURCE", "SELECT_HUB"];
|
|
4
|
+
type ScreenAction = (typeof SCREEN_ACTIONS)[number];
|
|
5
|
+
declare function isScreenAction(value: unknown): value is ScreenAction;
|
|
6
|
+
type ScreenDisplay = 'redirect' | 'popup';
|
|
7
|
+
interface ScreenData {
|
|
8
|
+
REGISTER_RESOURCE: {
|
|
9
|
+
url: string;
|
|
10
|
+
format: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
interface HubRef {
|
|
14
|
+
_id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
}
|
|
17
|
+
interface PickedResource {
|
|
18
|
+
datasetTitle: string;
|
|
19
|
+
resourceName: string;
|
|
20
|
+
format: string;
|
|
21
|
+
accessibility: 'OPEN' | 'PROTECTED' | 'PAID';
|
|
22
|
+
url: string;
|
|
23
|
+
requiresToken: boolean;
|
|
24
|
+
hasAccess: boolean;
|
|
25
|
+
}
|
|
26
|
+
interface ScreenAnswers {
|
|
27
|
+
SELECT_SUBSCRIPTION: {
|
|
28
|
+
subscription: {
|
|
29
|
+
_id: string;
|
|
30
|
+
status: 'ACTIVE' | 'PENDING';
|
|
31
|
+
externalReference: string;
|
|
32
|
+
};
|
|
33
|
+
subscribedHub: HubRef & {
|
|
34
|
+
role?: 'ADMIN' | 'MEMBER';
|
|
35
|
+
};
|
|
36
|
+
user?: {
|
|
37
|
+
_id: string;
|
|
38
|
+
email: string;
|
|
39
|
+
};
|
|
40
|
+
hasMultipleSubscriptions?: boolean;
|
|
41
|
+
};
|
|
42
|
+
DATA_PICKER: {
|
|
43
|
+
activeHub: HubRef;
|
|
44
|
+
resources: PickedResource[];
|
|
45
|
+
};
|
|
46
|
+
REGISTER_RESOURCE: {
|
|
47
|
+
activeHub: string;
|
|
48
|
+
dataset: {
|
|
49
|
+
datasetId: string;
|
|
50
|
+
datasetTitle?: string;
|
|
51
|
+
};
|
|
52
|
+
resource: {
|
|
53
|
+
resourceId: string;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
SELECT_HUB: {
|
|
57
|
+
hub: HubRef;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
type ScreenResult<A extends ScreenAction = ScreenAction> = {
|
|
61
|
+
action: A;
|
|
62
|
+
result: 'SUCCESS';
|
|
63
|
+
answer: ScreenAnswers[A];
|
|
64
|
+
} | {
|
|
65
|
+
action: A;
|
|
66
|
+
result: 'CANCELLED' | 'FAILURE';
|
|
67
|
+
answer?: undefined;
|
|
68
|
+
error?: string;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
interface SessionUser {
|
|
72
|
+
sub: string;
|
|
73
|
+
email: string;
|
|
74
|
+
name?: string;
|
|
75
|
+
appUserId?: string;
|
|
76
|
+
}
|
|
77
|
+
interface HubSubscription {
|
|
78
|
+
subscriptionId: string;
|
|
79
|
+
status: 'ACTIVE' | 'PENDING';
|
|
80
|
+
planName: string;
|
|
81
|
+
planId?: string;
|
|
82
|
+
}
|
|
83
|
+
type Session = {
|
|
84
|
+
signedIn: false;
|
|
85
|
+
} | {
|
|
86
|
+
signedIn: true;
|
|
87
|
+
user: SessionUser;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
declare const DEFAULT_BASE_PATH = "/clearly-hub";
|
|
91
|
+
declare const DEFAULT_HUB_URL = "https://hub.clearly.app";
|
|
92
|
+
declare const DEFAULT_AUTH_URL = "https://auth.clearly.app";
|
|
93
|
+
declare const DEFAULT_ISSUER = "https://cognito-idp.eu-central-1.amazonaws.com/eu-central-1_1fM1Zd9mJ";
|
|
94
|
+
declare const ROUTES: {
|
|
95
|
+
readonly signIn: "/sign-in";
|
|
96
|
+
readonly callback: "/callback";
|
|
97
|
+
readonly signOut: "/sign-out";
|
|
98
|
+
readonly session: "/session";
|
|
99
|
+
readonly open: "/open";
|
|
100
|
+
readonly answer: "/answer";
|
|
101
|
+
readonly result: "/result";
|
|
102
|
+
};
|
|
103
|
+
declare const ANSWER_CHANNEL = "clearly-hub-answers";
|
|
104
|
+
interface AnswerMessage {
|
|
105
|
+
ref: string;
|
|
106
|
+
result: ScreenResult;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
interface SignedInPerson {
|
|
110
|
+
sub: string;
|
|
111
|
+
email: string;
|
|
112
|
+
name?: string;
|
|
113
|
+
}
|
|
114
|
+
interface ClearlyHubOptions {
|
|
115
|
+
clientId: string;
|
|
116
|
+
m2mClientId?: string;
|
|
117
|
+
m2mClientSecret?: string;
|
|
118
|
+
appUrl: string;
|
|
119
|
+
secret: string;
|
|
120
|
+
basePath?: string;
|
|
121
|
+
hubUrl?: string;
|
|
122
|
+
urls?: Partial<ClearlyHubUrls>;
|
|
123
|
+
signedOutUrl?: string;
|
|
124
|
+
onSignIn?: (person: SignedInPerson) => Promise<string | void> | string | void;
|
|
125
|
+
onAnswer?: (result: ScreenResult, context: {
|
|
126
|
+
user?: SessionUser;
|
|
127
|
+
}) => Promise<void> | void;
|
|
128
|
+
fetch?: typeof fetch;
|
|
129
|
+
}
|
|
130
|
+
interface ClearlyHubUrls {
|
|
131
|
+
screens: string;
|
|
132
|
+
api: string;
|
|
133
|
+
usage: string;
|
|
134
|
+
publicKey: string;
|
|
135
|
+
auth: string;
|
|
136
|
+
issuer: string;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
interface AppSubscription extends HubSubscription {
|
|
140
|
+
hubId: string;
|
|
141
|
+
hubName: string;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
type CookieSource = Request | {
|
|
145
|
+
headers: Record<string, string | string[] | undefined>;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
declare function clearlyHub(options: ClearlyHubOptions): {
|
|
149
|
+
handler: (request: Request) => Promise<Response>;
|
|
150
|
+
express: () => (req: http.IncomingMessage & {
|
|
151
|
+
originalUrl?: string;
|
|
152
|
+
}, res: http.ServerResponse, next?: (error?: unknown) => void) => Promise<void>;
|
|
153
|
+
getUser(request: CookieSource): Promise<SessionUser | null>;
|
|
154
|
+
getUserToken: (request: CookieSource) => Promise<string | undefined>;
|
|
155
|
+
fetchAsUser(request: CookieSource, url: string, init?: RequestInit): Promise<Response>;
|
|
156
|
+
getAppToken: () => Promise<string>;
|
|
157
|
+
getSubscriptions: () => Promise<AppSubscription[]>;
|
|
158
|
+
getSubscription(hubId: string): Promise<AppSubscription | null>;
|
|
159
|
+
reportUsage({ request, hubId, quantity, }: {
|
|
160
|
+
request: CookieSource;
|
|
161
|
+
hubId: string;
|
|
162
|
+
quantity?: number;
|
|
163
|
+
}): Promise<void>;
|
|
164
|
+
};
|
|
165
|
+
type ClearlyHub = ReturnType<typeof clearlyHub>;
|
|
166
|
+
|
|
167
|
+
export { ANSWER_CHANNEL, DEFAULT_AUTH_URL, DEFAULT_BASE_PATH, DEFAULT_HUB_URL, DEFAULT_ISSUER, ROUTES, SCREEN_ACTIONS, clearlyHub, isScreenAction };
|
|
168
|
+
export type { AnswerMessage, AppSubscription, ClearlyHub, ClearlyHubOptions, ClearlyHubUrls, CookieSource, HubRef, HubSubscription, PickedResource, ScreenAction, ScreenAnswers, ScreenData, ScreenDisplay, ScreenResult, Session, SessionUser, SignedInPerson };
|