Skip to content

Commit 1c2ff2f

Browse files
authoredOct 4, 2022
Merge pull request #42 from spring-media/SPR-20295
SPR-20295 adding new types for non auth fetch and timeout
2 parents 6a856c9 + 59d78f0 commit 1c2ff2f

File tree

6 files changed

+9314
-40
lines changed

6 files changed

+9314
-40
lines changed
 

‎.github/workflows/pull_request.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ jobs:
1818
- name: Checkout branch
1919
if: github.event.action == 'opened' || github.event.action == 'edited' || github.event.action == 'synchronize'
2020
uses: actions/checkout@v1.2.0
21-
22-
- name: Set Node.js 10.x
21+
22+
- name: Set Node.js 16
2323
if: github.event.action == 'opened' || github.event.action == 'edited' || github.event.action == 'synchronize'
2424
uses: actions/setup-node@v1
2525
with:
26-
node-version: '10.x'
26+
node-version: "16"
2727

2828
- name: Install npm
2929
if: github.event.action == 'opened' || github.event.action == 'edited' || github.event.action == 'synchronize'
@@ -54,11 +54,11 @@ jobs:
5454
git config --global user.email "ps-support-og@moveoffice.com"
5555
git merge ${{ github.event.pull_request.head.sha }} -m"prchecker" --stat
5656
57-
- name: Set Node.js 10.x
57+
- name: Set Node.js 16
5858
if: github.event.action == 'opened' || github.event.action == 'edited' || github.event.action == 'synchronize'
5959
uses: actions/setup-node@v1
6060
with:
61-
node-version: '10.x'
61+
node-version: "16"
6262

6363
- name: Install npm
6464
if: github.event.action == 'opened' || github.event.action == 'edited' || github.event.action == 'synchronize'

‎.github/workflows/push_master.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ jobs:
1212
- name: Checkout branch
1313
uses: actions/checkout@v1.2.0
1414

15-
- name: Set Node.js 10.x
15+
- name: Set Node.js 16
1616
uses: actions/setup-node@v1
1717
with:
18-
node-version: '10.x'
18+
node-version: "16"
1919

2020
- name: Install npm
2121
run: npm ci
@@ -30,10 +30,10 @@ jobs:
3030
- name: Checkout branch
3131
uses: actions/checkout@v1.2.0
3232

33-
- name: Set Node.js 10.x
33+
- name: Set Node.js 16
3434
uses: actions/setup-node@v1
3535
with:
36-
node-version: '10.x'
36+
node-version: "16"
3737

3838
- name: config npm
3939
run: |

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
/.rpt2_cache
55

66
.idea
7+
8+
.dcc*

‎README.md

+12-9
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@ ps-web-apis is a client side library to interface with ps services on ps support
99
# Usage
1010

1111
```javascript
12-
import {whoamiV1} from '@spring-media/ps-web-apis'
13-
14-
whoamiV1().then(whoami => {
15-
console.log(`user login status: ${whoami.isLoggedIn() ? 'logged in' : 'logged out'}`)
16-
}).catch(() => {
17-
console.error('handle unavilability of whoami api')
18-
});
12+
import { whoamiV1 } from "@spring-media/ps-web-apis";
13+
14+
whoamiV1()
15+
.then((whoami) => {
16+
console.log(
17+
`user login status: ${whoami.isLoggedIn() ? "logged in" : "logged out"}`
18+
);
19+
})
20+
.catch(() => {
21+
console.error("handle unavilability of whoami api");
22+
});
1923
```
2024

2125
# Building
2226

2327
```
24-
npm i
28+
npm i
2529
npm run build
2630
```
27-

‎package-lock.json

+9,268-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/ps-web-apis.ts

+23-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { TealiumData } from "./model";
1+
import { provide } from "./apiprovide";
22

3-
function requireApi<T>(name: string): Promise<T> {
3+
function requirePackage<T>(name: string): Promise<T> {
44
// -- START -- static loader
55
const unresolvedPackages = {} as any;
66
const providedPackages = {} as any;
@@ -48,13 +48,21 @@ export interface WhoamiUserInfo {
4848
export interface PurchaseData {
4949
entitlements: [string];
5050
}
51+
export type FetchOptions = RequestInit & { timeout?: number };
52+
53+
/**
54+
* Custom fetch interface which includes the possibility to customize timeouts for fetch requests
55+
*/
56+
export type Fetch = (input: RequestInfo, init?: FetchOptions) => Promise<Response>;
5157

5258
export interface WhoamiV1 {
5359
/**
5460
* will assert valid not outdated session before fetch will be done. backend credentials will be added automatically
5561
* an error is resolved if session is invalid and not refeshable (= user logged out)
62+
* Important: as of version 1.9.9 all requests are timeout after 5s by default.
63+
* Can be changed by adding the field timeout to the FetchOptions Interface
5664
*/
57-
authorizedFetch: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
65+
authorizedFetch: Fetch;
5866
/**
5967
* gives information if user is currently loggedin from ui perspective
6068
*/
@@ -100,6 +108,17 @@ export interface WhoamiV1 {
100108
getUnsafePurchaseData(): Promise<PurchaseData>;
101109
}
102110

111+
export interface UtilsV1 {
112+
fetchWithTimeout: Fetch;
113+
}
114+
103115
export function whoamiV1(): Promise<WhoamiV1> {
104-
return requireApi("whoami:v1");
116+
return requirePackage("whoami:v1");
105117
}
118+
119+
export function utilsV1(): Promise<UtilsV1> {
120+
return requirePackage("utils:v1");
121+
}
122+
123+
export const provideApi = provide;
124+
export const requireApi = requirePackage;

0 commit comments

Comments
 (0)
Please sign in to comment.