@atlasauth/capacitor 0.1.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.
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ /**
3
+ * The Capacitor session token store.
4
+ *
5
+ * The web SDK keeps its short-lived JWT in memory and lets the browser carry the
6
+ * refresh token in an HttpOnly cookie. A Capacitor app — a WebView with no cookie
7
+ * jar against the FAPI origin — has to put the session somewhere the app chooses,
8
+ * and WHERE it lives is a security decision this SDK must not make for the app.
9
+ *
10
+ * So the SDK depends only on the small {@link TokenStore} interface below (the
11
+ * same three-method shape the `@atlasauth/js` native-session manager persists
12
+ * through) and ships two adapters: an in-memory default and a
13
+ * `@capacitor/preferences` one. `@capacitor/preferences` is an OPTIONAL peer, so
14
+ * its surface is declared structurally ({@link PreferencesPlugin}) and the app
15
+ * passes the real plugin in — the package compiles, typechecks and tests without
16
+ * it installed.
17
+ *
18
+ * ⚠️ `@capacitor/preferences` is NOT encrypted at rest (UserDefaults /
19
+ * SharedPreferences). For production, back the store with a secure-storage
20
+ * community plugin — e.g. `@capacitor-community/secure-storage` or
21
+ * `capacitor-secure-storage-plugin` — behind this same {@link TokenStore}
22
+ * interface. See {@link createPreferencesTokenStore} for the drop-in shape.
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.DEFAULT_SESSION_KEY = void 0;
26
+ exports.createPreferencesTokenStore = createPreferencesTokenStore;
27
+ exports.createInMemoryTokenStore = createInMemoryTokenStore;
28
+ /** The default key the serialized native session is stored under. */
29
+ exports.DEFAULT_SESSION_KEY = 'atlas.native_session';
30
+ /**
31
+ * Build a {@link TokenStore} backed by `@capacitor/preferences`, keyed by `key`.
32
+ * The app imports the plugin and passes it in — the SDK never imports
33
+ * `@capacitor/preferences` itself, so it stays an optional peer:
34
+ *
35
+ * ```ts
36
+ * import { Preferences } from '@capacitor/preferences';
37
+ * import { createPreferencesTokenStore } from '@atlasauth/capacitor';
38
+ *
39
+ * const store = createPreferencesTokenStore(Preferences);
40
+ * ```
41
+ *
42
+ * Preferences is plaintext at rest; swap a secure-storage plugin behind this same
43
+ * interface for production (see the module header).
44
+ */
45
+ function createPreferencesTokenStore(preferences, key = exports.DEFAULT_SESSION_KEY) {
46
+ return {
47
+ getToken: async () => (await preferences.get({ key })).value ?? null,
48
+ setToken: (value) => preferences.set({ key, value }),
49
+ clearToken: () => preferences.remove({ key }),
50
+ };
51
+ }
52
+ /**
53
+ * A process-memory {@link TokenStore}. The zero-config default so the SDK runs
54
+ * out of the box in tests and prototypes — but it does NOT survive an app
55
+ * restart, so ship {@link createPreferencesTokenStore} (or a secure-storage
56
+ * adapter) in production.
57
+ */
58
+ function createInMemoryTokenStore() {
59
+ let token = null;
60
+ return {
61
+ getToken: () => token,
62
+ setToken: (next) => {
63
+ token = next;
64
+ },
65
+ clearToken: () => {
66
+ token = null;
67
+ },
68
+ };
69
+ }
70
+ //# sourceMappingURL=token-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-store.js","sourceRoot":"","sources":["../src/token-store.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;AAsCH,kEASC;AAQD,4DAWC;AA9CD,qEAAqE;AACxD,QAAA,mBAAmB,GAAG,sBAAsB,CAAC;AAE1D;;;;;;;;;;;;;;GAcG;AACH,SAAgB,2BAA2B,CACzC,WAA8B,EAC9B,MAAc,2BAAmB;IAEjC,OAAO;QACL,QAAQ,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,WAAW,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI;QACpE,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;QACpD,UAAU,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC;KAC9C,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAgB,wBAAwB;IACtC,IAAI,KAAK,GAAkB,IAAI,CAAC;IAChC,OAAO;QACL,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK;QACrB,QAAQ,EAAE,CAAC,IAAY,EAAE,EAAE;YACzB,KAAK,GAAG,IAAI,CAAC;QACf,CAAC;QACD,UAAU,EAAE,GAAG,EAAE;YACf,KAAK,GAAG,IAAI,CAAC;QACf,CAAC;KACF,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@atlasauth/capacitor",
3
+ "version": "0.1.0",
4
+ "main": "./dist/index.js",
5
+ "types": "./dist/index.d.ts",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "default": "./dist/index.js"
10
+ },
11
+ "./package.json": "./package.json"
12
+ },
13
+ "dependencies": {
14
+ "@atlasauth/js": "0.2.0"
15
+ },
16
+ "peerDependencies": {
17
+ "@capacitor/core": ">=6",
18
+ "@capacitor/browser": ">=6",
19
+ "@capacitor/app": ">=6",
20
+ "@capacitor/preferences": ">=6"
21
+ },
22
+ "peerDependenciesMeta": {
23
+ "@capacitor/core": {
24
+ "optional": true
25
+ },
26
+ "@capacitor/browser": {
27
+ "optional": true
28
+ },
29
+ "@capacitor/app": {
30
+ "optional": true
31
+ },
32
+ "@capacitor/preferences": {
33
+ "optional": true
34
+ }
35
+ },
36
+ "devDependencies": {
37
+ "@capacitor/app": "^6.0.2",
38
+ "@capacitor/browser": "^6.0.5",
39
+ "@capacitor/core": "^6.2.1",
40
+ "@capacitor/preferences": "^6.0.3",
41
+ "typescript": "^5.6.3",
42
+ "vitest": "^2.1.4"
43
+ },
44
+ "publishConfig": {
45
+ "access": "public"
46
+ },
47
+ "files": [
48
+ "dist",
49
+ "README.md"
50
+ ],
51
+ "scripts": {
52
+ "build": "tsc -p tsconfig.build.json",
53
+ "typecheck": "tsc -p tsconfig.json --noEmit",
54
+ "test": "vitest run"
55
+ }
56
+ }