@telia-ace/widget-id-hub 1.1.120-rc.12 → 1.1.120-rc.14
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/id-hub-client.d.ts +15 -21
- package/index.d.ts +1 -0
- package/index.js +1 -12
- package/index.mjs +119 -44
- package/package.json +2 -2
- package/types.d.ts +50 -0
package/id-hub-client.d.ts
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
completionData?: {
|
|
3
|
-
user: {
|
|
4
|
-
givenName: string;
|
|
5
|
-
name: string;
|
|
6
|
-
ssn: string;
|
|
7
|
-
surname: string;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
idhubEIDToken?: string;
|
|
11
|
-
orderRef: string;
|
|
12
|
-
status: string;
|
|
13
|
-
substatus?: string;
|
|
14
|
-
};
|
|
1
|
+
import { IDHubStatus, AuthResponse, CollectResponse } from './types';
|
|
15
2
|
export declare class IDHubClient {
|
|
16
|
-
private url;
|
|
17
|
-
private maxRetries;
|
|
3
|
+
private readonly url;
|
|
4
|
+
private readonly maxRetries;
|
|
5
|
+
private readonly config;
|
|
18
6
|
private orderRef;
|
|
19
|
-
private tunnistusUrl;
|
|
20
7
|
constructor(config: any);
|
|
21
|
-
auth(): Promise<
|
|
22
|
-
|
|
23
|
-
|
|
8
|
+
auth(): Promise<AuthResponse>;
|
|
9
|
+
collect(): Promise<CollectResponse>;
|
|
10
|
+
cancel(): Promise<{
|
|
11
|
+
status: IDHubStatus;
|
|
12
|
+
errorMessage: string;
|
|
13
|
+
} | {
|
|
14
|
+
status?: undefined;
|
|
15
|
+
errorMessage?: undefined;
|
|
16
|
+
}>;
|
|
17
|
+
private static getHeaders;
|
|
18
|
+
private collectOnce;
|
|
24
19
|
}
|
|
25
|
-
export {};
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,12 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
2
|
-
"clientName": "idhub-web-1.0.0",
|
|
3
|
-
"register": {
|
|
4
|
-
"clientType": "ACEWIDGET",
|
|
5
|
-
"agentId": "ACEWIDGET",
|
|
6
|
-
"userName": "ACEWIDGET"
|
|
7
|
-
}
|
|
8
|
-
}`,method:"POST"})).json();return console.log("\x1B[31mID-Hub \x1B[32m - Initializing result",t),this.tunnistusUrl=t.tunnistusURL,this.orderRef=t.orderRef,this.tunnistusUrl}catch{return}}async collectPolling(){let e=this.maxRetries,t;do await new Promise(s=>setTimeout(s,1e3)),t=await this.collect(),e--;while(t.status=="pending"&&e>0);return t}async collect(){if(this.orderRef==="")throw new Error("OrderRef is missing");const t=await(await fetch(this.url+"/collect",{headers:{accept:"application/json","accept-language":"sv-SE,sv;q=0.9,en-US;q=0.8,en;q=0.7","content-type":"application/json"},body:`{
|
|
9
|
-
"clientName": "idhub-web-1.0.0",
|
|
10
|
-
"orderRef": "${this.orderRef}",
|
|
11
|
-
"method": "auth"
|
|
12
|
-
}`,method:"POST"})).json();return console.log("\x1B[31mID-Hub \x1B[32m - Collect result",t),t}}exports.IDHubClient=i;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var a=(s=>(s.Tunnistus="tunnistus",s.BankId="bankid",s.Freja="freja",s))(a||{}),r=(s=>(s.Pending="pending",s.Authenticated="authenticated",s.Error="error",s))(r||{});class u{constructor(e){this.orderRef="",this.config=e,this.url=`${e==null?void 0:e.idHubUrl}/${e==null?void 0:e.idHubCustomerKey}/${e==null?void 0:e.idHubOrgKey}/${e==null?void 0:e.idHubEidType.toLowerCase()}`,this.maxRetries=e.idHubMaxRetries??300}async auth(){try{const e=await fetch(`${this.url}/auth`,{headers:u.getHeaders(),body:JSON.stringify({clientName:"idhub-web-1.0.0",register:{clientType:"ACEWIDGET",agentId:"ACEWIDGET",userName:"ACEWIDGET"}}),method:"POST"});if(!e.ok)return{status:r.Error,errorMessage:`Auth failed with response: ${e.status} ${e.statusText}`};const t=await e.json();switch(this.orderRef=t.orderRef,this.config.idHubEidType){case a.Tunnistus:return{tunnistusURL:t.tunnistusURL,status:r.Pending};case a.BankId:return{autoStartToken:t.autoStartToken,status:r.Pending};case a.Freja:throw new Error(`${a.Freja} is not implemented`);default:throw new Error(`The service ${this.config.idHubEidType} is not implemented`)}}catch(e){return{status:r.Error,errorMessage:`Auth failed. Error: ${e}`}}}async collect(){for(let e=0;e<this.maxRetries;e++){await new Promise(i=>setTimeout(i,1e3));const t=await this.collectOnce();if(t&&t.status!==r.Pending)return t}return{status:r.Error}}async cancel(){try{return this.orderRef?(await fetch(`${this.url}/cancel`,{headers:u.getHeaders(),body:JSON.stringify({clientName:"idhub-web-1.0.0",orderRef:this.orderRef,method:"auth"}),method:"POST"}),{}):{status:r.Error,errorMessage:"Missing order reference."}}catch(e){return{status:r.Error,errorMessage:`Cancel failed. Error: ${e}`}}}static getHeaders(){return{accept:"application/json","accept-language":"sv-SE,sv;q=0.9,en-US;q=0.8,en;q=0.7","content-type":"application/json"}}async collectOnce(){try{if(!this.orderRef)return{status:r.Error,errorMessage:"Missing order reference."};const e=await fetch(`${this.url}/collect`,{headers:u.getHeaders(),body:JSON.stringify({clientName:"idhub-web-1.0.0",orderRef:this.orderRef,method:"auth"}),method:"POST"});if(!e.ok)return{status:r.Error,errorMessage:`Collect failed with response: ${e.status} ${e.statusText}`};const t=await e.json();return t.status===r.Error?{status:r.Error,subStatus:t.subStatus??void 0}:t}catch(e){return{status:r.Error,errorMessage:`Collect failed. Error: ${e}`}}}}exports.IDHubAuthService=a;exports.IDHubClient=u;exports.IDHubStatus=r;
|
package/index.mjs
CHANGED
|
@@ -1,57 +1,132 @@
|
|
|
1
|
-
|
|
1
|
+
var a = /* @__PURE__ */ ((s) => (s.Tunnistus = "tunnistus", s.BankId = "bankid", s.Freja = "freja", s))(a || {}), r = /* @__PURE__ */ ((s) => (s.Pending = "pending", s.Authenticated = "authenticated", s.Error = "error", s))(r || {});
|
|
2
|
+
class i {
|
|
2
3
|
constructor(e) {
|
|
3
|
-
this.
|
|
4
|
+
this.orderRef = "", this.config = e, this.url = `${e == null ? void 0 : e.idHubUrl}/${e == null ? void 0 : e.idHubCustomerKey}/${e == null ? void 0 : e.idHubOrgKey}/${e == null ? void 0 : e.idHubEidType.toLowerCase()}`, this.maxRetries = e.idHubMaxRetries ?? 300;
|
|
4
5
|
}
|
|
6
|
+
// ==========
|
|
7
|
+
// ID-HUB API
|
|
8
|
+
// ==========
|
|
5
9
|
async auth() {
|
|
6
|
-
console.log("\x1B[31mID-Hub \x1B[32m - Initializing auth");
|
|
7
10
|
try {
|
|
8
|
-
const
|
|
9
|
-
headers:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
const e = await fetch(`${this.url}/auth`, {
|
|
12
|
+
headers: i.getHeaders(),
|
|
13
|
+
body: JSON.stringify({
|
|
14
|
+
clientName: "idhub-web-1.0.0",
|
|
15
|
+
register: {
|
|
16
|
+
clientType: "ACEWIDGET",
|
|
17
|
+
agentId: "ACEWIDGET",
|
|
18
|
+
userName: "ACEWIDGET"
|
|
19
|
+
}
|
|
20
|
+
}),
|
|
21
|
+
method: "POST"
|
|
22
|
+
});
|
|
23
|
+
if (!e.ok)
|
|
24
|
+
return {
|
|
25
|
+
status: r.Error,
|
|
26
|
+
errorMessage: `Auth failed with response: ${e.status} ${e.statusText}`
|
|
27
|
+
};
|
|
28
|
+
const t = await e.json();
|
|
29
|
+
switch (this.orderRef = t.orderRef, this.config.idHubEidType) {
|
|
30
|
+
case a.Tunnistus:
|
|
31
|
+
return {
|
|
32
|
+
tunnistusURL: t.tunnistusURL,
|
|
33
|
+
status: r.Pending
|
|
34
|
+
};
|
|
35
|
+
case a.BankId:
|
|
36
|
+
return {
|
|
37
|
+
autoStartToken: t.autoStartToken,
|
|
38
|
+
status: r.Pending
|
|
39
|
+
};
|
|
40
|
+
case a.Freja:
|
|
41
|
+
throw new Error(`${a.Freja} is not implemented`);
|
|
42
|
+
default:
|
|
43
|
+
throw new Error(
|
|
44
|
+
`The service ${this.config.idHubEidType} is not implemented`
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
} catch (e) {
|
|
48
|
+
return {
|
|
49
|
+
status: r.Error,
|
|
50
|
+
errorMessage: `Auth failed. Error: ${e}`
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async collect() {
|
|
55
|
+
for (let e = 0; e < this.maxRetries; e++) {
|
|
56
|
+
await new Promise((n) => setTimeout(n, 1e3));
|
|
57
|
+
const t = await this.collectOnce();
|
|
58
|
+
if (t && t.status !== r.Pending)
|
|
59
|
+
return t;
|
|
60
|
+
}
|
|
61
|
+
return { status: r.Error };
|
|
20
62
|
}
|
|
21
|
-
|
|
63
|
+
async cancel() {
|
|
64
|
+
try {
|
|
65
|
+
return this.orderRef ? (await fetch(`${this.url}/cancel`, {
|
|
66
|
+
headers: i.getHeaders(),
|
|
67
|
+
body: JSON.stringify({
|
|
68
|
+
clientName: "idhub-web-1.0.0",
|
|
69
|
+
orderRef: this.orderRef,
|
|
70
|
+
method: "auth"
|
|
71
|
+
}),
|
|
22
72
|
method: "POST"
|
|
23
|
-
}))
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
73
|
+
}), {}) : {
|
|
74
|
+
status: r.Error,
|
|
75
|
+
errorMessage: "Missing order reference."
|
|
76
|
+
};
|
|
77
|
+
} catch (e) {
|
|
78
|
+
return {
|
|
79
|
+
status: r.Error,
|
|
80
|
+
errorMessage: `Cancel failed. Error: ${e}`
|
|
81
|
+
};
|
|
27
82
|
}
|
|
28
83
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
84
|
+
// =================
|
|
85
|
+
// UTILITY FUNCTIONS
|
|
86
|
+
// =================
|
|
87
|
+
static getHeaders() {
|
|
88
|
+
return {
|
|
89
|
+
accept: "application/json",
|
|
90
|
+
"accept-language": "sv-SE,sv;q=0.9,en-US;q=0.8,en;q=0.7",
|
|
91
|
+
"content-type": "application/json"
|
|
92
|
+
};
|
|
35
93
|
}
|
|
36
|
-
async
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
94
|
+
async collectOnce() {
|
|
95
|
+
try {
|
|
96
|
+
if (!this.orderRef)
|
|
97
|
+
return {
|
|
98
|
+
status: r.Error,
|
|
99
|
+
errorMessage: "Missing order reference."
|
|
100
|
+
};
|
|
101
|
+
const e = await fetch(`${this.url}/collect`, {
|
|
102
|
+
headers: i.getHeaders(),
|
|
103
|
+
body: JSON.stringify({
|
|
104
|
+
clientName: "idhub-web-1.0.0",
|
|
105
|
+
orderRef: this.orderRef,
|
|
106
|
+
method: "auth"
|
|
107
|
+
}),
|
|
108
|
+
method: "POST"
|
|
109
|
+
});
|
|
110
|
+
if (!e.ok)
|
|
111
|
+
return {
|
|
112
|
+
status: r.Error,
|
|
113
|
+
errorMessage: `Collect failed with response: ${e.status} ${e.statusText}`
|
|
114
|
+
};
|
|
115
|
+
const t = await e.json();
|
|
116
|
+
return t.status === r.Error ? {
|
|
117
|
+
status: r.Error,
|
|
118
|
+
subStatus: t.subStatus ?? void 0
|
|
119
|
+
} : t;
|
|
120
|
+
} catch (e) {
|
|
121
|
+
return {
|
|
122
|
+
status: r.Error,
|
|
123
|
+
errorMessage: `Collect failed. Error: ${e}`
|
|
124
|
+
};
|
|
125
|
+
}
|
|
53
126
|
}
|
|
54
127
|
}
|
|
55
128
|
export {
|
|
56
|
-
|
|
129
|
+
a as IDHubAuthService,
|
|
130
|
+
i as IDHubClient,
|
|
131
|
+
r as IDHubStatus
|
|
57
132
|
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telia-ace/widget-id-hub",
|
|
3
|
-
"version": "1.1.120-rc.
|
|
3
|
+
"version": "1.1.120-rc.14",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@telia-ace/widget-core-flamingo": "1.1.120-rc.
|
|
5
|
+
"@telia-ace/widget-core-flamingo": "1.1.120-rc.14"
|
|
6
6
|
},
|
|
7
7
|
"main": "./index.js",
|
|
8
8
|
"module": "./index.mjs",
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export type ApiAuthResponse = {
|
|
2
|
+
orderRef: string;
|
|
3
|
+
method: Method;
|
|
4
|
+
tunnistusURL?: string;
|
|
5
|
+
autoStartToken?: string;
|
|
6
|
+
};
|
|
7
|
+
export type ApiCollectResponse = {
|
|
8
|
+
orderRef: string;
|
|
9
|
+
status: IDHubStatus;
|
|
10
|
+
subStatus?: IdHubSubStatus;
|
|
11
|
+
idhubEIDToken?: string;
|
|
12
|
+
};
|
|
13
|
+
export type AuthResponse = {
|
|
14
|
+
status: IDHubStatus;
|
|
15
|
+
tunnistusURL?: string;
|
|
16
|
+
autoStartToken?: string;
|
|
17
|
+
errorMessage?: string;
|
|
18
|
+
};
|
|
19
|
+
export type CollectResponse = {
|
|
20
|
+
status: IDHubStatus;
|
|
21
|
+
subStatus?: IdHubSubStatus;
|
|
22
|
+
idhubEIDToken?: string;
|
|
23
|
+
errorMessage?: string;
|
|
24
|
+
};
|
|
25
|
+
export declare enum IDHubAuthService {
|
|
26
|
+
Tunnistus = "tunnistus",
|
|
27
|
+
BankId = "bankid",
|
|
28
|
+
Freja = "freja"
|
|
29
|
+
}
|
|
30
|
+
export declare enum Method {
|
|
31
|
+
Sign = "sign",
|
|
32
|
+
Auth = "auth"
|
|
33
|
+
}
|
|
34
|
+
export declare enum IDHubStatus {
|
|
35
|
+
Pending = "pending",
|
|
36
|
+
Authenticated = "authenticated",
|
|
37
|
+
Error = "error"
|
|
38
|
+
}
|
|
39
|
+
export declare enum IdHubSubStatus {
|
|
40
|
+
Started = "started",
|
|
41
|
+
DeliveredToMobile = "deliveredToMobile",
|
|
42
|
+
Cancelled = "cancelled",
|
|
43
|
+
RpCancelled = "rpCancelled",
|
|
44
|
+
Expired = "expired",
|
|
45
|
+
Rejected = "rejected",
|
|
46
|
+
CertificateErr = "certificateErr",
|
|
47
|
+
StartFailed = "startFailed",
|
|
48
|
+
UserDeclinedCall = "userDeclinedCall",
|
|
49
|
+
NotSupportedByUserApp = "notSupportedByUserApp"
|
|
50
|
+
}
|