pushwave-client 0.3.4 → 0.3.5
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/register/registerPushWave.js +2 -2
- package/dist/utils/fetch.d.ts +8 -2
- package/dist/utils/fetch.js +13 -28
- package/dist/utils/pushwaveSettings.js +1 -1
- package/package.json +1 -1
- package/src/register/registerPushWave.ts +2 -2
- package/src/utils/fetch.ts +25 -43
- package/src/utils/pushwaveSettings.ts +2 -2
- package/dist/attestation/getAndroidSignature.d.ts +0 -0
- package/dist/attestation/getAndroidSignature.js +0 -1
- package/dist/attestation/getApplicationSignature.d.ts +0 -1
- package/dist/attestation/getApplicationSignature.js +0 -9
- package/dist/attestation/getIosDeviceCheck.d.ts +0 -1
- package/dist/attestation/getIosDeviceCheck.js +0 -2
- package/dist/registerPushWave.d.ts +0 -15
- package/dist/registerPushWave.js +0 -53
- package/dist/utils/validation.d.ts +0 -0
- package/dist/utils/validation.js +0 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.registerPushWave = registerPushWave;
|
|
4
|
-
const fetch_1 = require("../utils/fetch");
|
|
5
4
|
const expoToken_1 = require("../utils/expoToken");
|
|
6
5
|
const react_native_1 = require("react-native");
|
|
7
6
|
const pwLogger_1 = require("../utils/pwLogger");
|
|
8
7
|
const apiKeyCheck_1 = require("../utils/apiKeyCheck");
|
|
9
8
|
const index_1 = require("../attestation/index");
|
|
9
|
+
const fetch_1 = require("../utils/fetch");
|
|
10
10
|
async function registerPushWave({ apiKey }) {
|
|
11
11
|
const OS = react_native_1.Platform.OS;
|
|
12
12
|
if ((0, apiKeyCheck_1.isSecretKey)(apiKey)) {
|
|
@@ -34,7 +34,7 @@ async function registerPushWave({ apiKey }) {
|
|
|
34
34
|
environment: __DEV__ ? "development" : "production"
|
|
35
35
|
};
|
|
36
36
|
try {
|
|
37
|
-
const res = await (0, fetch_1.
|
|
37
|
+
const res = await (0, fetch_1.fetchApi)("PUT", path, { data: options });
|
|
38
38
|
return {
|
|
39
39
|
success: true,
|
|
40
40
|
message: res.message,
|
package/dist/utils/fetch.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type FetchMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
2
|
+
type FetchParams = Record<string, string | number | boolean | undefined>;
|
|
3
|
+
type FetchData = Record<string, any>;
|
|
4
|
+
export declare function fetchApi<TResponse>(method: FetchMethod, path: string, { params, data }?: {
|
|
5
|
+
params?: FetchParams;
|
|
6
|
+
data?: FetchData;
|
|
7
|
+
}): Promise<TResponse>;
|
|
8
|
+
export {};
|
package/dist/utils/fetch.js
CHANGED
|
@@ -1,33 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.fetchApiGet = fetchApiGet;
|
|
3
|
+
exports.fetchApi = fetchApi;
|
|
5
4
|
const BASE_URL = "https://api.pushwave.dev/v1/public/";
|
|
6
|
-
async function
|
|
7
|
-
const url = BASE_URL + path;
|
|
8
|
-
const res = await fetch(url, {
|
|
9
|
-
method: "POST",
|
|
10
|
-
headers: {
|
|
11
|
-
"Content-Type": "application/json",
|
|
12
|
-
},
|
|
13
|
-
body: JSON.stringify(data),
|
|
14
|
-
});
|
|
15
|
-
const text = await res.text();
|
|
16
|
-
let json = null;
|
|
17
|
-
try {
|
|
18
|
-
json = text ? JSON.parse(text) : null;
|
|
19
|
-
}
|
|
20
|
-
catch (err) {
|
|
21
|
-
// JSON empty/invalid
|
|
22
|
-
}
|
|
23
|
-
if (!res.ok) {
|
|
24
|
-
const apiError = (json?.error ?? json?.message ?? "");
|
|
25
|
-
const message = `(${res.status}) ${apiError}`.trim();
|
|
26
|
-
throw new Error(message);
|
|
27
|
-
}
|
|
28
|
-
return json;
|
|
29
|
-
}
|
|
30
|
-
async function fetchApiGet(path, params) {
|
|
5
|
+
async function fetchApi(method, path, { params, data } = {}) {
|
|
31
6
|
const search = params
|
|
32
7
|
? new URLSearchParams(Object.entries(params).reduce((acc, [key, value]) => {
|
|
33
8
|
if (value === undefined)
|
|
@@ -36,8 +11,18 @@ async function fetchApiGet(path, params) {
|
|
|
36
11
|
return acc;
|
|
37
12
|
}, {})).toString()
|
|
38
13
|
: "";
|
|
14
|
+
console.log("Go fetch !");
|
|
39
15
|
const url = BASE_URL + path + (search ? `?${search}` : "");
|
|
40
|
-
const
|
|
16
|
+
const headers = {};
|
|
17
|
+
const body = data !== undefined && method !== "GET" ? JSON.stringify(data) : undefined;
|
|
18
|
+
if (body) {
|
|
19
|
+
headers["Content-Type"] = "application/json";
|
|
20
|
+
}
|
|
21
|
+
const res = await fetch(url, {
|
|
22
|
+
method,
|
|
23
|
+
headers,
|
|
24
|
+
body,
|
|
25
|
+
});
|
|
41
26
|
const text = await res.text();
|
|
42
27
|
let json = null;
|
|
43
28
|
try {
|
|
@@ -6,7 +6,7 @@ const fetch_1 = require("./fetch");
|
|
|
6
6
|
const pwLogger_1 = require("./pwLogger");
|
|
7
7
|
const pushwaveSettingsPromise = (async () => {
|
|
8
8
|
try {
|
|
9
|
-
return await (0, fetch_1.
|
|
9
|
+
return await (0, fetch_1.fetchApi)("GET", "pushwave-config", { params: { platform: react_native_1.Platform.OS } });
|
|
10
10
|
}
|
|
11
11
|
catch (e) {
|
|
12
12
|
// log si besoin
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { fetchApiPost } from "../utils/fetch";
|
|
2
1
|
import { getExpoToken } from "../utils/expoToken";
|
|
3
2
|
import { Platform } from "react-native";
|
|
4
3
|
import { PWLogger } from "../utils/pwLogger";
|
|
5
4
|
import { isSecretKey } from "../utils/apiKeyCheck";
|
|
6
5
|
import { RegisterPushWaveClient, RegisterPushWaveDTO, RegisterPushWaveResponse } from "./registerPushWave.dto";
|
|
7
6
|
import { getApplicationAttestation } from "../attestation/index";
|
|
7
|
+
import { fetchApi } from "../utils/fetch";
|
|
8
8
|
|
|
9
9
|
export async function registerPushWave(
|
|
10
10
|
{ apiKey }: RegisterPushWaveClient
|
|
@@ -46,7 +46,7 @@ export async function registerPushWave(
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
try {
|
|
49
|
-
const res: RegisterPushWaveResponse = await
|
|
49
|
+
const res: RegisterPushWaveResponse = await fetchApi("PUT", path, { data: options })
|
|
50
50
|
|
|
51
51
|
return {
|
|
52
52
|
success: true,
|
package/src/utils/fetch.ts
CHANGED
|
@@ -1,57 +1,39 @@
|
|
|
1
1
|
const BASE_URL = "https://api.pushwave.dev/v1/public/";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
): Promise<TResponse> {
|
|
7
|
-
|
|
8
|
-
const url = BASE_URL + path;
|
|
9
|
-
|
|
10
|
-
const res = await fetch(url, {
|
|
11
|
-
method: "POST",
|
|
12
|
-
headers: {
|
|
13
|
-
"Content-Type": "application/json",
|
|
14
|
-
},
|
|
15
|
-
body: JSON.stringify(data),
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
const text = await res.text();
|
|
19
|
-
let json: any = null;
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
json = text ? JSON.parse(text) : null;
|
|
23
|
-
} catch (err) {
|
|
24
|
-
// JSON empty/invalid
|
|
25
|
-
}
|
|
3
|
+
type FetchMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
4
|
+
type FetchParams = Record<string, string | number | boolean | undefined>;
|
|
5
|
+
type FetchData = Record<string, any>;
|
|
26
6
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const message = `(${res.status}) ${apiError}`.trim();
|
|
31
|
-
|
|
32
|
-
throw new Error(message);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return json as TResponse;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export async function fetchApiGet<TResponse>(
|
|
7
|
+
export async function fetchApi<TResponse>(
|
|
8
|
+
method: FetchMethod,
|
|
39
9
|
path: string,
|
|
40
|
-
params
|
|
10
|
+
{ params, data }: { params?: FetchParams; data?: FetchData } = {}
|
|
41
11
|
): Promise<TResponse> {
|
|
42
12
|
const search = params
|
|
43
13
|
? new URLSearchParams(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
14
|
+
Object.entries(params).reduce<Record<string, string>>((acc, [key, value]) => {
|
|
15
|
+
if (value === undefined) return acc;
|
|
16
|
+
acc[key] = String(value);
|
|
17
|
+
return acc;
|
|
18
|
+
}, {})
|
|
19
|
+
).toString()
|
|
50
20
|
: "";
|
|
51
21
|
|
|
22
|
+
console.log("Go fetch !");
|
|
23
|
+
|
|
52
24
|
const url = BASE_URL + path + (search ? `?${search}` : "");
|
|
53
25
|
|
|
54
|
-
const
|
|
26
|
+
const headers: Record<string, string> = {};
|
|
27
|
+
const body = data !== undefined && method !== "GET" ? JSON.stringify(data) : undefined;
|
|
28
|
+
if (body) {
|
|
29
|
+
headers["Content-Type"] = "application/json";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const res = await fetch(url, {
|
|
33
|
+
method,
|
|
34
|
+
headers,
|
|
35
|
+
body,
|
|
36
|
+
});
|
|
55
37
|
|
|
56
38
|
const text = await res.text();
|
|
57
39
|
let json: any = null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Platform } from "react-native";
|
|
2
|
-
import {
|
|
2
|
+
import { fetchApi } from "./fetch";
|
|
3
3
|
import { PWLogger } from "./pwLogger";
|
|
4
4
|
|
|
5
5
|
export type PushwaveSettings = {
|
|
@@ -9,7 +9,7 @@ export type PushwaveSettings = {
|
|
|
9
9
|
|
|
10
10
|
const pushwaveSettingsPromise: Promise<PushwaveSettings> = (async () => {
|
|
11
11
|
try {
|
|
12
|
-
return await
|
|
12
|
+
return await fetchApi("GET", "pushwave-config", { params: { platform: Platform.OS } });
|
|
13
13
|
} catch (e) {
|
|
14
14
|
// log si besoin
|
|
15
15
|
PWLogger.warn(`Unable to load PushWave configuration: ${e}`)
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function getApplicationSignature(): void;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function (): any;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export interface RegisterPushWaveClient {
|
|
2
|
-
apiKey: string;
|
|
3
|
-
}
|
|
4
|
-
export interface RegisterPushWaveResponse {
|
|
5
|
-
success: boolean;
|
|
6
|
-
message?: string;
|
|
7
|
-
}
|
|
8
|
-
export interface RegisterPushWaveDTO {
|
|
9
|
-
apiKey: string;
|
|
10
|
-
expoToken: string;
|
|
11
|
-
platform: string;
|
|
12
|
-
appAttestation?: any;
|
|
13
|
-
environment: "development" | "production";
|
|
14
|
-
}
|
|
15
|
-
export default function registerPushWave({ apiKey }: RegisterPushWaveClient): Promise<RegisterPushWaveResponse>;
|
package/dist/registerPushWave.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.default = registerPushWave;
|
|
7
|
-
const fetch_1 = require("./utils/fetch");
|
|
8
|
-
const expoToken_1 = require("./utils/expoToken");
|
|
9
|
-
const getApplicationAttestation_1 = __importDefault(require("./attestation/getApplicationAttestation"));
|
|
10
|
-
const react_native_1 = require("react-native");
|
|
11
|
-
const pwLogger_1 = require("./utils/pwLogger");
|
|
12
|
-
const apiKeyCheck_1 = require("./utils/apiKeyCheck");
|
|
13
|
-
async function registerPushWave({ apiKey }) {
|
|
14
|
-
if ((0, apiKeyCheck_1.isSecretKey)(apiKey)) {
|
|
15
|
-
const warn = `\x1b[0m You are using your SECRET API key in a client environment. This key must NEVER be embedded in a mobile app.`;
|
|
16
|
-
pwLogger_1.PWLogger.warn(warn);
|
|
17
|
-
}
|
|
18
|
-
const expoToken = await (0, expoToken_1.getExpoToken)();
|
|
19
|
-
if (!expoToken) {
|
|
20
|
-
const message = "could not get ExpoToken";
|
|
21
|
-
pwLogger_1.PWLogger.error(message);
|
|
22
|
-
return {
|
|
23
|
-
success: false,
|
|
24
|
-
message: "[PushWaveClient] Error: " + message
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
const appAttestation = await (0, getApplicationAttestation_1.default)(apiKey);
|
|
28
|
-
if (appAttestation.status === "disabled")
|
|
29
|
-
pwLogger_1.PWLogger.warn(`(${react_native_1.Platform.OS}) could not get attestation: ${appAttestation.reason}`);
|
|
30
|
-
const path = "/v1/expo-tokens";
|
|
31
|
-
const options = {
|
|
32
|
-
apiKey: apiKey,
|
|
33
|
-
expoToken: expoToken,
|
|
34
|
-
platform: react_native_1.Platform.OS,
|
|
35
|
-
appAttestation: appAttestation,
|
|
36
|
-
environment: __DEV__ ? "development" : "production"
|
|
37
|
-
};
|
|
38
|
-
try {
|
|
39
|
-
const res = await (0, fetch_1.fetchApi)(path, options);
|
|
40
|
-
return {
|
|
41
|
-
success: true,
|
|
42
|
-
message: res.message,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
catch (err) {
|
|
46
|
-
const e = err;
|
|
47
|
-
pwLogger_1.PWLogger.error(e.message);
|
|
48
|
-
return {
|
|
49
|
-
success: false,
|
|
50
|
-
message: e.message,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
File without changes
|
package/dist/utils/validation.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|