@oblax/platform-mobile 1.0.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/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/platform.d.ts +32 -0
- package/dist/platform.d.ts.map +1 -0
- package/dist/platform.js +60 -0
- package/dist/platform.js.map +1 -0
- package/package.json +55 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { OblaxModulePlugin } from '@oblax/core';
|
|
2
|
+
import { MobilePlatform } from './platform.js';
|
|
3
|
+
export { MobilePlatform } from './platform.js';
|
|
4
|
+
/**
|
|
5
|
+
* Mobile platform factory.
|
|
6
|
+
*
|
|
7
|
+
* Registers the mobile platform with the Oblax SDK. Tokens are persisted in
|
|
8
|
+
* AsyncStorage so the session survives app restarts.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { Oblax } from '@oblax/core'
|
|
13
|
+
* import { PlatformMobile } from '@oblax/platform-mobile'
|
|
14
|
+
* import { Auth } from '@oblax/auth'
|
|
15
|
+
*
|
|
16
|
+
* const oblax = new Oblax({
|
|
17
|
+
* endpoint: 'https://api.my-app.oblax.io',
|
|
18
|
+
* clientId: 'my-mobile-app',
|
|
19
|
+
* modules: [PlatformMobile(), Auth({ realm: 'mobile' })],
|
|
20
|
+
* })
|
|
21
|
+
*
|
|
22
|
+
* await oblax.auth.session.create({ email: 'alice@example.com', password: 'secret' })
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function PlatformMobile(): OblaxModulePlugin<'platform', MobilePlatform>;
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,cAAc,IAAI,iBAAiB,CAAC,UAAU,EAAE,cAAc,CAAC,CAK9E"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { MobilePlatform } from './platform.js';
|
|
2
|
+
export { MobilePlatform } from './platform.js';
|
|
3
|
+
/**
|
|
4
|
+
* Mobile platform factory.
|
|
5
|
+
*
|
|
6
|
+
* Registers the mobile platform with the Oblax SDK. Tokens are persisted in
|
|
7
|
+
* AsyncStorage so the session survives app restarts.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { Oblax } from '@oblax/core'
|
|
12
|
+
* import { PlatformMobile } from '@oblax/platform-mobile'
|
|
13
|
+
* import { Auth } from '@oblax/auth'
|
|
14
|
+
*
|
|
15
|
+
* const oblax = new Oblax({
|
|
16
|
+
* endpoint: 'https://api.my-app.oblax.io',
|
|
17
|
+
* clientId: 'my-mobile-app',
|
|
18
|
+
* modules: [PlatformMobile(), Auth({ realm: 'mobile' })],
|
|
19
|
+
* })
|
|
20
|
+
*
|
|
21
|
+
* await oblax.auth.session.create({ email: 'alice@example.com', password: 'secret' })
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function PlatformMobile() {
|
|
25
|
+
return {
|
|
26
|
+
name: 'platform',
|
|
27
|
+
create: () => new MobilePlatform(),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,cAAc,EAAE;KACnC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AuthPayload, CredentialDelivery, OblaxPlatform } from '@oblax/core';
|
|
2
|
+
/**
|
|
3
|
+
* Mobile platform (React Native).
|
|
4
|
+
*
|
|
5
|
+
* Auth strategy: `Authorization: Bearer <token>` header with tokens persisted
|
|
6
|
+
* in AsyncStorage so the user stays logged in across app restarts.
|
|
7
|
+
*
|
|
8
|
+
* Suitable for: React Native, Expo.
|
|
9
|
+
*
|
|
10
|
+
* Security note: AsyncStorage is **not encrypted**. The access token is
|
|
11
|
+
* short-lived, but the refresh token is long-lived. For apps with higher
|
|
12
|
+
* security requirements, replace AsyncStorage with encrypted storage
|
|
13
|
+
* (Keychain/Keystore) for the refresh token.
|
|
14
|
+
*/
|
|
15
|
+
export declare class MobilePlatform implements OblaxPlatform {
|
|
16
|
+
/** Credentials are returned in the JSON body and persisted to AsyncStorage. */
|
|
17
|
+
readonly credentialDelivery: CredentialDelivery;
|
|
18
|
+
/**
|
|
19
|
+
* Called by the HTTP client when a 401 is received.
|
|
20
|
+
* The auth module overwrites this after initialization to wire in
|
|
21
|
+
* `session.refresh()`. Default: no-op (returns false).
|
|
22
|
+
*/
|
|
23
|
+
onTokenExpired: () => Promise<boolean>;
|
|
24
|
+
prepareRequest(init: RequestInit): Promise<RequestInit>;
|
|
25
|
+
onAuthSuccess(payload: AuthPayload): Promise<void>;
|
|
26
|
+
onAuthClear(): Promise<void>;
|
|
27
|
+
/** `true` when an access token exists in AsyncStorage. */
|
|
28
|
+
isAuthenticated(): Promise<boolean>;
|
|
29
|
+
/** The stored refresh token, or `null` if not available. */
|
|
30
|
+
getRefreshToken(): Promise<string | null>;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=platform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAOjF;;;;;;;;;;;;GAYG;AACH,qBAAa,cAAe,YAAW,aAAa;IAClD,+EAA+E;IAC/E,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,CAAU;IAEzD;;;;OAIG;IACH,cAAc,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAA+B;IAE/D,cAAc,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAWvD,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IASlD,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAIlC,0DAA0D;IACpD,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;IAKzC,4DAA4D;IACtD,eAAe,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAGhD"}
|
package/dist/platform.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import AsyncStorageDefault from '@react-native-async-storage/async-storage';
|
|
2
|
+
const AsyncStorage = AsyncStorageDefault;
|
|
3
|
+
const ACCESS_TOKEN_KEY = 'oblax_access_token';
|
|
4
|
+
const REFRESH_TOKEN_KEY = 'oblax_refresh_token';
|
|
5
|
+
/**
|
|
6
|
+
* Mobile platform (React Native).
|
|
7
|
+
*
|
|
8
|
+
* Auth strategy: `Authorization: Bearer <token>` header with tokens persisted
|
|
9
|
+
* in AsyncStorage so the user stays logged in across app restarts.
|
|
10
|
+
*
|
|
11
|
+
* Suitable for: React Native, Expo.
|
|
12
|
+
*
|
|
13
|
+
* Security note: AsyncStorage is **not encrypted**. The access token is
|
|
14
|
+
* short-lived, but the refresh token is long-lived. For apps with higher
|
|
15
|
+
* security requirements, replace AsyncStorage with encrypted storage
|
|
16
|
+
* (Keychain/Keystore) for the refresh token.
|
|
17
|
+
*/
|
|
18
|
+
export class MobilePlatform {
|
|
19
|
+
constructor() {
|
|
20
|
+
/** Credentials are returned in the JSON body and persisted to AsyncStorage. */
|
|
21
|
+
this.credentialDelivery = 'token';
|
|
22
|
+
/**
|
|
23
|
+
* Called by the HTTP client when a 401 is received.
|
|
24
|
+
* The auth module overwrites this after initialization to wire in
|
|
25
|
+
* `session.refresh()`. Default: no-op (returns false).
|
|
26
|
+
*/
|
|
27
|
+
this.onTokenExpired = () => Promise.resolve(false);
|
|
28
|
+
}
|
|
29
|
+
async prepareRequest(init) {
|
|
30
|
+
const accessToken = await AsyncStorage.getItem(ACCESS_TOKEN_KEY);
|
|
31
|
+
if (!accessToken)
|
|
32
|
+
return init;
|
|
33
|
+
const existing = (init.headers ?? {});
|
|
34
|
+
return {
|
|
35
|
+
...init,
|
|
36
|
+
headers: { ...existing, Authorization: `Bearer ${accessToken}` },
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
async onAuthSuccess(payload) {
|
|
40
|
+
if (payload.oblax_access_token !== undefined) {
|
|
41
|
+
await AsyncStorage.setItem(ACCESS_TOKEN_KEY, payload.oblax_access_token);
|
|
42
|
+
}
|
|
43
|
+
if (payload.oblax_refresh_token !== undefined) {
|
|
44
|
+
await AsyncStorage.setItem(REFRESH_TOKEN_KEY, payload.oblax_refresh_token);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async onAuthClear() {
|
|
48
|
+
await AsyncStorage.multiRemove([ACCESS_TOKEN_KEY, REFRESH_TOKEN_KEY]);
|
|
49
|
+
}
|
|
50
|
+
/** `true` when an access token exists in AsyncStorage. */
|
|
51
|
+
async isAuthenticated() {
|
|
52
|
+
const accessToken = await AsyncStorage.getItem(ACCESS_TOKEN_KEY);
|
|
53
|
+
return accessToken !== null;
|
|
54
|
+
}
|
|
55
|
+
/** The stored refresh token, or `null` if not available. */
|
|
56
|
+
async getRefreshToken() {
|
|
57
|
+
return AsyncStorage.getItem(REFRESH_TOKEN_KEY);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=platform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,MAAM,2CAA2C,CAAA;AAI3E,MAAM,YAAY,GAAG,mBAAoD,CAAA;AAEzE,MAAM,gBAAgB,GAAG,oBAAoB,CAAA;AAC7C,MAAM,iBAAiB,GAAG,qBAAqB,CAAA;AAE/C;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,cAAc;IAA3B;QACE,+EAA+E;QACtE,uBAAkB,GAAuB,OAAO,CAAA;QAEzD;;;;WAIG;QACH,mBAAc,GAA2B,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAoCvE,CAAC;IAlCC,KAAK,CAAC,cAAc,CAAC,IAAiB;QACpC,MAAM,WAAW,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAA;QAChE,IAAI,CAAC,WAAW;YAAE,OAAO,IAAI,CAAA;QAE7B,MAAM,QAAQ,GAAG,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAA2B,CAAA;QAC/D,OAAO;YACL,GAAG,IAAI;YACP,OAAO,EAAE,EAAE,GAAG,QAAQ,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE;SACjE,CAAA;IACH,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,OAAoB;QACtC,IAAI,OAAO,CAAC,kBAAkB,KAAK,SAAS,EAAE,CAAC;YAC7C,MAAM,YAAY,CAAC,OAAO,CAAC,gBAAgB,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAA;QAC1E,CAAC;QACD,IAAI,OAAO,CAAC,mBAAmB,KAAK,SAAS,EAAE,CAAC;YAC9C,MAAM,YAAY,CAAC,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAA;QAC5E,CAAC;IACH,CAAC;IAED,KAAK,CAAC,WAAW;QACf,MAAM,YAAY,CAAC,WAAW,CAAC,CAAC,gBAAgB,EAAE,iBAAiB,CAAC,CAAC,CAAA;IACvE,CAAC;IAED,0DAA0D;IAC1D,KAAK,CAAC,eAAe;QACnB,MAAM,WAAW,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAA;QAChE,OAAO,WAAW,KAAK,IAAI,CAAA;IAC7B,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,eAAe;QACnB,OAAO,YAAY,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAA;IAChD,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@oblax/platform-mobile",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Oblax SDK — mobile platform (React Native, AsyncStorage token persistence)",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Oblax SDK for JavaScript Team",
|
|
8
|
+
"url": "https://docs.oblax.io/docs/getting-started/your-first-sdk-call"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/oblaxio/oblax-sdk-js#readme",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/oblaxio/oblax-sdk-js.git",
|
|
14
|
+
"directory": "packages/platform-mobile"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/oblaxio/oblax-sdk-js/issues"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"oblax",
|
|
21
|
+
"sdk",
|
|
22
|
+
"platform",
|
|
23
|
+
"mobile",
|
|
24
|
+
"react-native"
|
|
25
|
+
],
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"import": "./dist/index.js",
|
|
32
|
+
"types": "./dist/index.d.ts"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist"
|
|
37
|
+
],
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@react-native-async-storage/async-storage": "^1.19.0",
|
|
43
|
+
"@oblax/core": "1.0.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@react-native-async-storage/async-storage": "^1.19.0",
|
|
47
|
+
"typescript": "^5.5.0",
|
|
48
|
+
"@oblax/core": "1.0.0"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsc --build tsconfig.json",
|
|
52
|
+
"typecheck": "tsc --build tsconfig.json --dry",
|
|
53
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo"
|
|
54
|
+
}
|
|
55
|
+
}
|