Skip to content

Commit f183489

Browse files
committed
Merge branch 'release-25.4' into 'main'
Release 25.4 See merge request nwac/sdk-ts!95
2 parents ddf1a5b + d47d4e2 commit f183489

31 files changed

+1945
-493
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## Version 4.2.0
4+
5+
Changes:
6+
- Introduced support for Geofencing API
7+
- Introduced support for Number Verification API
8+
9+
Fixes:
10+
- Updated mocking libraries to deal with deprecated dependencies
11+
312
## Version 4.1.1
413

514
Fixes:

Jenkinsfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pipeline {
5656
NAC_TOKEN_PROD = credentials('NAC_TOKEN_PROD')
5757
TEAMS_WEBHOOK = credentials('TEAMS_WEBHOOK')
5858
NPM_AUTH_TOKEN = credentials('NPM_AUTH_TOKEN')
59+
SDK_NOTIFICATION_SERVER_URL = credentials('SDK_NOTIFICATION_SERVER_URL')
5960
SONAR_PATH = "/opt/sonar-scanner/bin"
6061
SONAR_TOKEN = "sonar-token"
6162
}
@@ -119,7 +120,7 @@ pipeline {
119120
script {
120121
sh """
121122
env | grep gitlab
122-
https_proxy="http://fihel1d-proxy.emea.nsn-net.net:8080" npm run integration
123+
http_proxy="http://fihel1d-proxy.emea.nsn-net.net:8080" https_proxy="http://fihel1d-proxy.emea.nsn-net.net:8080" npm run integration
123124
"""
124125
}
125126
}

examples/number-verification.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import express, { Express, Request, Response } from "express";
2+
import { NetworkAsCodeClient } from "network-as-code";
3+
4+
5+
// Initialize the client object with your application key
6+
const client = new NetworkAsCodeClient("<your-application-key-here>");
7+
8+
9+
// Then, create a device object for the phone number you want to check */
10+
const device = client.devices.get({
11+
// The phone number accepts the "+" sign, but not spaces or "()" marks
12+
phoneNumber: "+3637123456"
13+
});
14+
15+
16+
/* This authorization_endpoint should be requested by the end user device and not in the backend
17+
of your application, since the requesting device is used to determine authorization
18+
for the particular device. You could, for example,
19+
handle this by presenting the user with a link or a button to click to initiate the redirect flow.
20+
You must provide a redirectUri, where the authorization code will be delivered.
21+
See the express example provided below.
22+
23+
You can add a state value of your choosing to test for CSRF attacks. Your application then should check,
24+
that the state value given to the authorization endpoint matches the one returned to the redirect uri.
25+
If the state values do not match, there has likely been a CSRF attack. In this case your application
26+
should return a 401 Unauthorized error code. */
27+
28+
const redirectUri = "https://my-example/redirect";
29+
const scope = "number-verification:verify";
30+
const loginHint = device.phoneNumber;
31+
const state = "foobar";
32+
33+
// create a callbacklink
34+
const callback = await client.authentication.createAuthenticationLink(
35+
redirectUri,
36+
scope,
37+
loginHint,
38+
state
39+
);
40+
41+
42+
// Example of a redirectUri to use to receive the authorization code from the authorization endpoint
43+
const app: Express = express();
44+
const port = process.env.PORT || 3000;
45+
46+
app.use(express.json());
47+
48+
app.get("/redirect", (req: Request, res: Response) => {
49+
res.send(`This is your authorization code: ${req.query.code}`)
50+
51+
res.status(200).end();
52+
});
53+
54+
app.listen(port, () => {
55+
console.log(`[server]: Server is running at http://localhost:${port}`);
56+
});
57+
58+
59+
60+
61+
// Add your authorization code here.
62+
const code = "NaC-authorization-code";
63+
64+
65+
/* You can use the Number Verification API with the obtained authorization code.
66+
The verifyNumber endpoint will respond with a true or false value. */
67+
const verificationResult = await device.verifyNumber(code);
68+
69+
console.log(verificationResult);
70+
71+
// The getPhoneNumber endpoint will respond with the phone number of the used Device.
72+
73+
const phoneNumber = await device.getPhoneNumber(code);
74+
75+
console.log(phoneNumber) // "+123456789"

examples/sim-swap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NetworkAsCodeClient } from "../src";
1+
import { NetworkAsCodeClient } from "network-as-code";
22

33
const client = new NetworkAsCodeClient("<your-token>");
44

integration-tests/configClient.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ export const configureClient = (): NetworkAsCodeClient => {
1212
);
1313
return client;
1414
}
15+
16+
export const configureNotificationServerUrl = () : string => {
17+
const notificationUrl = `${process.env["SDK_NOTIFICATION_SERVER_URL"]}typescript`;
18+
return notificationUrl
19+
}

integration-tests/congestionInsights.itest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ let device: Device;
99
beforeAll(() => {
1010
client = configureClient()
1111
device = client.devices.get({
12-
phoneNumber: "+3670123456",
12+
phoneNumber: "+3672123456",
1313
});
1414
});
1515

integration-tests/deviceStatus.itest.ts

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import { NetworkAsCodeClient } from "../src";
22
import "dotenv/config";
33
import { Device } from "../src/models/device";
4-
import { configureClient } from "./configClient";
4+
import { configureClient, configureNotificationServerUrl } from "./configClient";
5+
import { ProxyAgent } from "proxy-agent";
6+
import fetch from "node-fetch";
7+
58

69
let client: NetworkAsCodeClient;
710
let device: Device;
11+
let notificationUrl: string;
12+
let agent : ProxyAgent
13+
814

915
beforeAll(() => {
1016
client = configureClient();
@@ -16,20 +22,38 @@ beforeAll(() => {
1622
publicPort: 80,
1723
},
1824
});
25+
notificationUrl = configureNotificationServerUrl();
26+
agent = new ProxyAgent();
1927
});
2028

2129
describe("Device Status", () => {
2230
it("can create a connectivity subscription and delete it", async () => {
2331
const subscription = await client.deviceStatus.subscribe(
2432
device,
2533
"org.camaraproject.device-status.v0.connectivity-data",
26-
"https://example.com/notify"
34+
`${notificationUrl}/notify`
2735
);
28-
2936
expect(subscription.eventSubscriptionId).toBeDefined();
3037

38+
await new Promise(resolve => setTimeout(resolve, 5 * 1000));
39+
let notification = await fetch(`${notificationUrl}/device-status/get/${subscription.eventSubscriptionId}`,
40+
{
41+
method: "GET",
42+
agent: agent
43+
}
44+
);
45+
46+
const data = await notification.json();
47+
48+
expect(data).not.toBeNull();
49+
notification = await fetch(`${notificationUrl}/device-status/delete/${subscription.eventSubscriptionId}`,
50+
{
51+
method: 'DELETE',
52+
agent: agent
53+
});
54+
3155
subscription.delete();
32-
});
56+
},20 * 1000);
3357

3458
it("can create a connectivity subscription with expiry", async () => {
3559
const tomorrowDate = new Date(Date.now() + 24 * 60 * 60 * 1000);
@@ -38,7 +62,7 @@ describe("Device Status", () => {
3862
const subscription = await client.deviceStatus.subscribe(
3963
device,
4064
"org.camaraproject.device-status.v0.connectivity-data",
41-
"https://example.com/notify",
65+
`${notificationUrl}/notify`,
4266
{
4367
subscriptionExpireTime: tomorrowDate,
4468
}
@@ -48,14 +72,31 @@ describe("Device Status", () => {
4872
new Date(tomorrowDate.toISOString().replace(".000", ""))
4973
);
5074

75+
await new Promise(resolve => setTimeout(resolve, 5 * 1000));
76+
let notification = await fetch(`${notificationUrl}/device-status/get/${subscription.eventSubscriptionId}`,
77+
{
78+
method: "GET",
79+
agent: agent
80+
}
81+
);
82+
83+
const data = await notification.json();
84+
85+
expect(data).not.toBeNull();
86+
notification = await fetch(`${notificationUrl}/device-status/delete/${subscription.eventSubscriptionId}`,
87+
{
88+
method: 'DELETE',
89+
agent: agent
90+
});
91+
5192
subscription.delete();
52-
});
93+
},20 * 1000);
5394

5495
it("can create a connectivity subscription with other optional arguments", async () => {
5596
const subscription = await client.deviceStatus.subscribe(
5697
device,
5798
"org.camaraproject.device-status.v0.connectivity-data",
58-
"https://example.com/notify",
99+
`${notificationUrl}/notify`,
59100
{
60101
maxNumberOfReports: 2,
61102
notificationAuthToken: "my-token",
@@ -66,8 +107,25 @@ describe("Device Status", () => {
66107
expect(subscription.maxNumOfReports).toEqual(2);
67108
expect(subscription.notificationAuthToken).toEqual("my-token");
68109

110+
await new Promise(resolve => setTimeout(resolve, 5 * 1000));
111+
let notification = await fetch(`${notificationUrl}/device-status/get/${subscription.eventSubscriptionId}`,
112+
{
113+
method: "GET",
114+
agent: agent
115+
}
116+
);
117+
118+
const data = await notification.json();
119+
120+
expect(data).not.toBeNull();
121+
notification = await fetch(`${notificationUrl}/device-status/delete/${subscription.eventSubscriptionId}`,
122+
{
123+
method: 'DELETE',
124+
agent: agent
125+
});
126+
69127
subscription.delete();
70-
});
128+
},20 * 1000);
71129

72130
it("can get a subscription by id", async () => {
73131
const subscription = await client.deviceStatus.subscribe(

0 commit comments

Comments
 (0)