aeria-sdk 0.0.4 → 0.0.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.
@@ -11,4 +11,5 @@ export type AuthenticationPayload = {
11
11
  password: string;
12
12
  };
13
13
  export declare const authMemo: AuthenticationResult;
14
- export declare const authenticate: (config: InstanceConfig) => (payload: AuthenticationPayload) => Promise<unknown>;
14
+ export declare const authenticate: (config: InstanceConfig) => (payload: AuthenticationPayload) => Promise<any>;
15
+ export declare const signout: (config: InstanceConfig) => () => Promise<void>;
package/dist/cjs/auth.js CHANGED
@@ -1,18 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.authenticate = exports.authMemo = void 0;
3
+ exports.signout = exports.authenticate = exports.authMemo = void 0;
4
4
  const common_1 = require("@sonata-api/common");
5
5
  const http_1 = require("./http");
6
+ const utils_1 = require("./utils");
7
+ const storage_1 = require("./storage");
6
8
  exports.authMemo = {};
7
9
  const authenticate = (config) => async (payload) => {
8
- const response = await (0, http_1.request)(`${config.apiUrl}/user/authenticate`, payload);
10
+ const response = await (0, http_1.request)(config, `${(0, utils_1.apiUrl)(config)}/user/authenticate`, payload);
9
11
  const resultEither = response.data;
10
- if ((0, common_1.isLeft)(resultEither)) {
11
- //
12
- return;
12
+ if ((0, common_1.isRight)(resultEither)) {
13
+ const result = (0, common_1.unwrapEither)(resultEither);
14
+ (0, storage_1.getStorage)(config).set('auth', JSON.stringify(result));
13
15
  }
14
- const result = (0, common_1.unwrapEither)(resultEither);
15
- Object.assign(exports.authMemo, result);
16
- return result;
16
+ return resultEither;
17
17
  };
18
18
  exports.authenticate = authenticate;
19
+ const signout = (config) => async () => {
20
+ (0, storage_1.getStorage)(config).remove('auth');
21
+ };
22
+ exports.signout = signout;
@@ -1,2 +1,3 @@
1
+ import type { InstanceConfig } from './types';
1
2
  import { type RequestConfig } from '@sonata-api/common';
2
- export declare const request: <Return = any>(url: string, payload?: any, _config?: RequestConfig) => Promise<Return>;
3
+ export declare const request: <Return = any>(config: InstanceConfig, url: string, payload?: any, _requestConfig?: RequestConfig) => Promise<Return>;
package/dist/cjs/http.js CHANGED
@@ -2,22 +2,26 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.request = void 0;
4
4
  const common_1 = require("@sonata-api/common");
5
- const auth_1 = require("./auth");
6
- const request = (url, payload, _config) => {
7
- const config = Object.assign({}, _config);
8
- config.requestTransformer ??= async (url, payload, _params) => {
5
+ const storage_1 = require("./storage");
6
+ const request = (config, url, payload, _requestConfig) => {
7
+ const requestConfig = Object.assign({}, _requestConfig);
8
+ requestConfig.requestTransformer ??= async (url, payload, _params) => {
9
9
  const params = Object.assign({}, _params);
10
- if (auth_1.authMemo.token) {
10
+ const authVal = (0, storage_1.getStorage)(config).get('auth');
11
+ const auth = authVal
12
+ ? JSON.parse(authVal)
13
+ : {};
14
+ if (auth.token) {
11
15
  params.headers ??= {};
12
- switch (auth_1.authMemo.token.type) {
16
+ switch (auth.token.type) {
13
17
  case 'bearer': {
14
- params.headers.authorization = `Bearer ${auth_1.authMemo.token.content}`;
18
+ params.headers.authorization = `Bearer ${auth.token.content}`;
15
19
  break;
16
20
  }
17
21
  }
18
22
  }
19
23
  return (0, common_1.defaultRequestTransformer)(url, payload, params);
20
24
  };
21
- return (0, common_1.request)(url, payload, config);
25
+ return (0, common_1.request)(url, payload, requestConfig);
22
26
  };
23
27
  exports.request = request;
@@ -1,4 +1,5 @@
1
1
  export { topLevel as Aeria } from './topLevel';
2
2
  export * from '@sonata-api/common';
3
3
  export * from './topLevel';
4
- export * from '.aeria-sdk';
4
+ export * from './runtime';
5
+ export * from './storage';
package/dist/cjs/index.js CHANGED
@@ -19,5 +19,5 @@ var topLevel_1 = require("./topLevel");
19
19
  Object.defineProperty(exports, "Aeria", { enumerable: true, get: function () { return topLevel_1.topLevel; } });
20
20
  __exportStar(require("@sonata-api/common"), exports);
21
21
  __exportStar(require("./topLevel"), exports);
22
- // @ts-ignore
23
- __exportStar(require(".aeria-sdk"), exports);
22
+ __exportStar(require("./runtime"), exports);
23
+ __exportStar(require("./storage"), exports);
@@ -1,3 +1,4 @@
1
1
  import type { InstanceConfig } from './types';
2
- export declare const runtimeJs: (config: InstanceConfig) => string;
2
+ export declare const runtimeCjs: (config: InstanceConfig) => string;
3
+ export declare const runtimeEsm: (config: InstanceConfig) => string;
3
4
  export declare const mirror: (config: InstanceConfig) => Promise<void>;
@@ -3,11 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.mirror = exports.runtimeJs = void 0;
6
+ exports.mirror = exports.runtimeEsm = exports.runtimeCjs = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const common_1 = require("@sonata-api/common");
9
9
  const promises_1 = require("fs/promises");
10
10
  const topLevel_1 = require("./topLevel");
11
+ const utils_1 = require("./utils");
11
12
  const mirrorDts = (mirrorObj) => {
12
13
  const collections = mirrorObj.descriptions;
13
14
  return `import type {
@@ -71,18 +72,30 @@ declare module 'aeria-sdk' {
71
72
  }\n
72
73
  `;
73
74
  };
74
- const runtimeJs = (config) => `exports.url = '${(0, topLevel_1.apiUrl)(config)}'
75
- exports.aeria = require('aeria-sdk').Aeria(${JSON.stringify(config)})\n
76
- `;
77
- exports.runtimeJs = runtimeJs;
75
+ const runtimeCjs = (config) => `const { Aeria, getStorage } from 'aeria-sdk'
76
+ const config = ${JSON.stringify(config)}
77
+ exports.config = config
78
+ exports.url = '${(0, utils_1.apiUrl)(config)}'
79
+ exports.aeria = Aeria(config)
80
+ exports.storage = getStorage(config)
81
+ \n`;
82
+ exports.runtimeCjs = runtimeCjs;
83
+ const runtimeEsm = (config) => `import { Aeria, getStorage } from 'aeria-sdk'
84
+ export const config = ${JSON.stringify(config)}
85
+ export const url = '${(0, utils_1.apiUrl)(config)}'
86
+ export const aeria = Aeria(config)
87
+ export const storage = getStorage(config)
88
+ \n`;
89
+ exports.runtimeEsm = runtimeEsm;
78
90
  const mirror = async (config) => {
79
91
  const api = (0, topLevel_1.topLevel)(config);
80
- const runtimeBase = path_1.default.join(path_1.default.dirname(require.resolve('aeria-sdk')), '..', '..', '..', '.aeria-sdk');
92
+ const runtimeBase = path_1.default.dirname(require.resolve('aeria-sdk'));
81
93
  const mirror = (0, common_1.deserialize)(await api.describe({
82
94
  router: true
83
95
  }));
84
96
  await (0, promises_1.mkdir)(runtimeBase, { recursive: true });
85
97
  await (0, promises_1.writeFile)(path_1.default.join(process.cwd(), 'aeria-sdk.d.ts'), mirrorDts(mirror));
86
- await (0, promises_1.writeFile)(path_1.default.join(runtimeBase, 'index.js'), (0, exports.runtimeJs)(config));
98
+ await (0, promises_1.writeFile)(path_1.default.join(runtimeBase, '..', 'cjs', 'runtime.js'), (0, exports.runtimeCjs)(config));
99
+ await (0, promises_1.writeFile)(path_1.default.join(runtimeBase, '..', 'esm', 'runtime.js'), (0, exports.runtimeEsm)(config));
87
100
  };
88
101
  exports.mirror = mirror;
@@ -0,0 +1,9 @@
1
+ import type { InstanceConfig } from './types';
2
+ export declare const instanceConfig: InstanceConfig;
3
+ export declare const url = "";
4
+ export declare const aeria: {};
5
+ export declare const storage: {
6
+ get: (key: string) => string | null;
7
+ remove: (key: string) => void;
8
+ set: (key: string, value: string) => void;
9
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.storage = exports.aeria = exports.url = exports.instanceConfig = void 0;
4
+ exports.instanceConfig = {};
5
+ exports.url = '';
6
+ exports.aeria = {};
7
+ exports.storage = {};
@@ -0,0 +1,8 @@
1
+ import type { InstanceConfig } from './types';
2
+ export declare const storageMemo: Record<string, string>;
3
+ export declare const storageKey: (key: string, config: InstanceConfig) => string;
4
+ export declare const getStorage: (config: InstanceConfig) => {
5
+ get: (key: string) => string | null;
6
+ remove: (key: string) => void;
7
+ set: (key: string, value: string) => void;
8
+ };
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getStorage = exports.storageKey = exports.storageMemo = void 0;
4
+ exports.storageMemo = {};
5
+ const storageKey = (key, config) => {
6
+ const namespace = config.storage?.namespace || 'aeriaSdk';
7
+ return `${namespace}:${key}`;
8
+ };
9
+ exports.storageKey = storageKey;
10
+ const getStorage = (config) => {
11
+ const strategy = !config.storage?.strategy
12
+ ? 'memo'
13
+ : config.storage.strategy === 'localStorage' && !('localStorage' in globalThis)
14
+ ? 'memo'
15
+ : config.storage.strategy;
16
+ return {
17
+ get: (key) => {
18
+ switch (strategy) {
19
+ case 'memo':
20
+ return exports.storageMemo[key];
21
+ case 'localStorage':
22
+ return localStorage.getItem((0, exports.storageKey)(key, config));
23
+ }
24
+ },
25
+ remove: (key) => {
26
+ switch (strategy) {
27
+ case 'memo':
28
+ delete exports.storageMemo[key];
29
+ break;
30
+ case 'localStorage':
31
+ localStorage.removeItem((0, exports.storageKey)(key, config));
32
+ break;
33
+ }
34
+ },
35
+ set: (key, value) => {
36
+ switch (strategy) {
37
+ case 'memo':
38
+ exports.storageMemo[key] = value;
39
+ break;
40
+ case 'localStorage':
41
+ return localStorage.setItem((0, exports.storageKey)(key, config), value);
42
+ }
43
+ },
44
+ };
45
+ };
46
+ exports.getStorage = getStorage;
@@ -3,6 +3,7 @@ import { type AuthenticationPayload } from './auth';
3
3
  type UserFunctions = {
4
4
  user: TLOFunctions & {
5
5
  authenticate: (payload: AuthenticationPayload) => Promise<any>;
6
+ signout: () => Promise<void>;
6
7
  };
7
8
  };
8
9
  export type TLOFunctions = {
@@ -10,7 +11,7 @@ export type TLOFunctions = {
10
11
  };
11
12
  export type TopLevelObject = UserFunctions & {
12
13
  describe: (...args: any) => Promise<any>;
14
+ $currentUser: any;
13
15
  };
14
- export declare const apiUrl: (config: InstanceConfig) => string;
15
16
  export declare const topLevel: (config: InstanceConfig) => TopLevelObject;
16
17
  export {};
@@ -1,30 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.topLevel = exports.apiUrl = void 0;
3
+ exports.topLevel = void 0;
4
4
  const auth_1 = require("./auth");
5
5
  const http_1 = require("./http");
6
- const apiUrl = (config) => {
7
- if (typeof config.apiUrl === 'string') {
8
- return config.apiUrl;
9
- }
10
- return process.env.NODE_ENV === 'production'
11
- ? config.apiUrl.production
12
- : config.apiUrl.development;
13
- };
14
- exports.apiUrl = apiUrl;
6
+ const utils_1 = require("./utils");
15
7
  const topLevel = (config) => {
16
8
  const proxify = (target, parent) => new Proxy(target, {
17
9
  get: (_, key) => {
10
+ if (typeof key === 'symbol') {
11
+ return target[key];
12
+ }
18
13
  const endpoint = parent
19
14
  ? `${parent}/${key}`
20
15
  : `${key}`;
21
16
  switch (endpoint) {
22
17
  case 'user/authenticate': return (0, auth_1.authenticate)(config);
18
+ case 'user/signout': return (0, auth_1.signout)(config);
23
19
  }
24
20
  const fn = async (payload) => {
25
21
  const response = payload
26
- ? await (0, http_1.request)(`${(0, exports.apiUrl)(config)}/${endpoint}`, payload)
27
- : await (0, http_1.request)(`${(0, exports.apiUrl)(config)}/${endpoint}`);
22
+ ? await (0, http_1.request)(config, `${(0, utils_1.apiUrl)(config)}/${endpoint}`, payload)
23
+ : await (0, http_1.request)(config, `${(0, utils_1.apiUrl)(config)}/${endpoint}`);
28
24
  return response.data;
29
25
  };
30
26
  return proxify(fn, endpoint);
@@ -3,4 +3,8 @@ export type InstanceConfig = {
3
3
  production: string;
4
4
  development: string;
5
5
  };
6
+ storage?: {
7
+ strategy?: 'memo' | 'localStorage';
8
+ namespace?: string;
9
+ };
6
10
  };
@@ -0,0 +1,2 @@
1
+ import type { InstanceConfig } from './types';
2
+ export declare const apiUrl: (config: InstanceConfig) => string;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.apiUrl = void 0;
4
+ const apiUrl = (config) => {
5
+ if (typeof config.apiUrl === 'string') {
6
+ return config.apiUrl;
7
+ }
8
+ return process.env.NODE_ENV === 'production'
9
+ ? config.apiUrl.production
10
+ : config.apiUrl.development;
11
+ };
12
+ exports.apiUrl = apiUrl;
@@ -11,4 +11,5 @@ export type AuthenticationPayload = {
11
11
  password: string;
12
12
  };
13
13
  export declare const authMemo: AuthenticationResult;
14
- export declare const authenticate: (config: InstanceConfig) => (payload: AuthenticationPayload) => Promise<unknown>;
14
+ export declare const authenticate: (config: InstanceConfig) => (payload: AuthenticationPayload) => Promise<any>;
15
+ export declare const signout: (config: InstanceConfig) => () => Promise<void>;
package/dist/esm/auth.js CHANGED
@@ -1,14 +1,17 @@
1
- import { isLeft, unwrapEither } from '@sonata-api/common';
1
+ import { isRight, unwrapEither } from '@sonata-api/common';
2
2
  import { request } from './http';
3
+ import { apiUrl } from './utils';
4
+ import { getStorage } from './storage';
3
5
  export const authMemo = {};
4
6
  export const authenticate = (config) => async (payload) => {
5
- const response = await request(`${config.apiUrl}/user/authenticate`, payload);
7
+ const response = await request(config, `${apiUrl(config)}/user/authenticate`, payload);
6
8
  const resultEither = response.data;
7
- if (isLeft(resultEither)) {
8
- //
9
- return;
9
+ if (isRight(resultEither)) {
10
+ const result = unwrapEither(resultEither);
11
+ getStorage(config).set('auth', JSON.stringify(result));
10
12
  }
11
- const result = unwrapEither(resultEither);
12
- Object.assign(authMemo, result);
13
- return result;
13
+ return resultEither;
14
+ };
15
+ export const signout = (config) => async () => {
16
+ getStorage(config).remove('auth');
14
17
  };
@@ -1,2 +1,3 @@
1
+ import type { InstanceConfig } from './types';
1
2
  import { type RequestConfig } from '@sonata-api/common';
2
- export declare const request: <Return = any>(url: string, payload?: any, _config?: RequestConfig) => Promise<Return>;
3
+ export declare const request: <Return = any>(config: InstanceConfig, url: string, payload?: any, _requestConfig?: RequestConfig) => Promise<Return>;
package/dist/esm/http.js CHANGED
@@ -1,19 +1,23 @@
1
1
  import { request as originalRequest, defaultRequestTransformer } from '@sonata-api/common';
2
- import { authMemo } from './auth';
3
- export const request = (url, payload, _config) => {
4
- const config = Object.assign({}, _config);
5
- config.requestTransformer ??= async (url, payload, _params) => {
2
+ import { getStorage } from './storage';
3
+ export const request = (config, url, payload, _requestConfig) => {
4
+ const requestConfig = Object.assign({}, _requestConfig);
5
+ requestConfig.requestTransformer ??= async (url, payload, _params) => {
6
6
  const params = Object.assign({}, _params);
7
- if (authMemo.token) {
7
+ const authVal = getStorage(config).get('auth');
8
+ const auth = authVal
9
+ ? JSON.parse(authVal)
10
+ : {};
11
+ if (auth.token) {
8
12
  params.headers ??= {};
9
- switch (authMemo.token.type) {
13
+ switch (auth.token.type) {
10
14
  case 'bearer': {
11
- params.headers.authorization = `Bearer ${authMemo.token.content}`;
15
+ params.headers.authorization = `Bearer ${auth.token.content}`;
12
16
  break;
13
17
  }
14
18
  }
15
19
  }
16
20
  return defaultRequestTransformer(url, payload, params);
17
21
  };
18
- return originalRequest(url, payload, config);
22
+ return originalRequest(url, payload, requestConfig);
19
23
  };
@@ -1,4 +1,5 @@
1
1
  export { topLevel as Aeria } from './topLevel';
2
2
  export * from '@sonata-api/common';
3
3
  export * from './topLevel';
4
- export * from '.aeria-sdk';
4
+ export * from './runtime';
5
+ export * from './storage';
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { topLevel as Aeria } from './topLevel';
2
2
  export * from '@sonata-api/common';
3
3
  export * from './topLevel';
4
- // @ts-ignore
5
- export * from '.aeria-sdk';
4
+ export * from './runtime';
5
+ export * from './storage';
@@ -1,3 +1,4 @@
1
1
  import type { InstanceConfig } from './types';
2
- export declare const runtimeJs: (config: InstanceConfig) => string;
2
+ export declare const runtimeCjs: (config: InstanceConfig) => string;
3
+ export declare const runtimeEsm: (config: InstanceConfig) => string;
3
4
  export declare const mirror: (config: InstanceConfig) => Promise<void>;
@@ -1,7 +1,8 @@
1
1
  import path from 'path';
2
2
  import { deserialize } from '@sonata-api/common';
3
3
  import { writeFile, mkdir } from 'fs/promises';
4
- import { topLevel, apiUrl } from './topLevel';
4
+ import { topLevel } from './topLevel';
5
+ import { apiUrl } from './utils';
5
6
  const mirrorDts = (mirrorObj) => {
6
7
  const collections = mirrorObj.descriptions;
7
8
  return `import type {
@@ -65,16 +66,27 @@ declare module 'aeria-sdk' {
65
66
  }\n
66
67
  `;
67
68
  };
68
- export const runtimeJs = (config) => `exports.url = '${apiUrl(config)}'
69
- exports.aeria = require('aeria-sdk').Aeria(${JSON.stringify(config)})\n
70
- `;
69
+ export const runtimeCjs = (config) => `const { Aeria, getStorage } from 'aeria-sdk'
70
+ const config = ${JSON.stringify(config)}
71
+ exports.config = config
72
+ exports.url = '${apiUrl(config)}'
73
+ exports.aeria = Aeria(config)
74
+ exports.storage = getStorage(config)
75
+ \n`;
76
+ export const runtimeEsm = (config) => `import { Aeria, getStorage } from 'aeria-sdk'
77
+ export const config = ${JSON.stringify(config)}
78
+ export const url = '${apiUrl(config)}'
79
+ export const aeria = Aeria(config)
80
+ export const storage = getStorage(config)
81
+ \n`;
71
82
  export const mirror = async (config) => {
72
83
  const api = topLevel(config);
73
- const runtimeBase = path.join(path.dirname(require.resolve('aeria-sdk')), '..', '..', '..', '.aeria-sdk');
84
+ const runtimeBase = path.dirname(require.resolve('aeria-sdk'));
74
85
  const mirror = deserialize(await api.describe({
75
86
  router: true
76
87
  }));
77
88
  await mkdir(runtimeBase, { recursive: true });
78
89
  await writeFile(path.join(process.cwd(), 'aeria-sdk.d.ts'), mirrorDts(mirror));
79
- await writeFile(path.join(runtimeBase, 'index.js'), runtimeJs(config));
90
+ await writeFile(path.join(runtimeBase, '..', 'cjs', 'runtime.js'), runtimeCjs(config));
91
+ await writeFile(path.join(runtimeBase, '..', 'esm', 'runtime.js'), runtimeEsm(config));
80
92
  };
@@ -0,0 +1,9 @@
1
+ import type { InstanceConfig } from './types';
2
+ export declare const instanceConfig: InstanceConfig;
3
+ export declare const url = "";
4
+ export declare const aeria: {};
5
+ export declare const storage: {
6
+ get: (key: string) => string | null;
7
+ remove: (key: string) => void;
8
+ set: (key: string, value: string) => void;
9
+ };
@@ -0,0 +1,4 @@
1
+ export const instanceConfig = {};
2
+ export const url = '';
3
+ export const aeria = {};
4
+ export const storage = {};
@@ -0,0 +1,8 @@
1
+ import type { InstanceConfig } from './types';
2
+ export declare const storageMemo: Record<string, string>;
3
+ export declare const storageKey: (key: string, config: InstanceConfig) => string;
4
+ export declare const getStorage: (config: InstanceConfig) => {
5
+ get: (key: string) => string | null;
6
+ remove: (key: string) => void;
7
+ set: (key: string, value: string) => void;
8
+ };
@@ -0,0 +1,41 @@
1
+ export const storageMemo = {};
2
+ export const storageKey = (key, config) => {
3
+ const namespace = config.storage?.namespace || 'aeriaSdk';
4
+ return `${namespace}:${key}`;
5
+ };
6
+ export const getStorage = (config) => {
7
+ const strategy = !config.storage?.strategy
8
+ ? 'memo'
9
+ : config.storage.strategy === 'localStorage' && !('localStorage' in globalThis)
10
+ ? 'memo'
11
+ : config.storage.strategy;
12
+ return {
13
+ get: (key) => {
14
+ switch (strategy) {
15
+ case 'memo':
16
+ return storageMemo[key];
17
+ case 'localStorage':
18
+ return localStorage.getItem(storageKey(key, config));
19
+ }
20
+ },
21
+ remove: (key) => {
22
+ switch (strategy) {
23
+ case 'memo':
24
+ delete storageMemo[key];
25
+ break;
26
+ case 'localStorage':
27
+ localStorage.removeItem(storageKey(key, config));
28
+ break;
29
+ }
30
+ },
31
+ set: (key, value) => {
32
+ switch (strategy) {
33
+ case 'memo':
34
+ storageMemo[key] = value;
35
+ break;
36
+ case 'localStorage':
37
+ return localStorage.setItem(storageKey(key, config), value);
38
+ }
39
+ },
40
+ };
41
+ };
@@ -3,6 +3,7 @@ import { type AuthenticationPayload } from './auth';
3
3
  type UserFunctions = {
4
4
  user: TLOFunctions & {
5
5
  authenticate: (payload: AuthenticationPayload) => Promise<any>;
6
+ signout: () => Promise<void>;
6
7
  };
7
8
  };
8
9
  export type TLOFunctions = {
@@ -10,7 +11,7 @@ export type TLOFunctions = {
10
11
  };
11
12
  export type TopLevelObject = UserFunctions & {
12
13
  describe: (...args: any) => Promise<any>;
14
+ $currentUser: any;
13
15
  };
14
- export declare const apiUrl: (config: InstanceConfig) => string;
15
16
  export declare const topLevel: (config: InstanceConfig) => TopLevelObject;
16
17
  export {};
@@ -1,26 +1,23 @@
1
- import { authenticate } from './auth';
1
+ import { authenticate, signout } from './auth';
2
2
  import { request } from './http';
3
- export const apiUrl = (config) => {
4
- if (typeof config.apiUrl === 'string') {
5
- return config.apiUrl;
6
- }
7
- return process.env.NODE_ENV === 'production'
8
- ? config.apiUrl.production
9
- : config.apiUrl.development;
10
- };
3
+ import { apiUrl } from './utils';
11
4
  export const topLevel = (config) => {
12
5
  const proxify = (target, parent) => new Proxy(target, {
13
6
  get: (_, key) => {
7
+ if (typeof key === 'symbol') {
8
+ return target[key];
9
+ }
14
10
  const endpoint = parent
15
11
  ? `${parent}/${key}`
16
12
  : `${key}`;
17
13
  switch (endpoint) {
18
14
  case 'user/authenticate': return authenticate(config);
15
+ case 'user/signout': return signout(config);
19
16
  }
20
17
  const fn = async (payload) => {
21
18
  const response = payload
22
- ? await request(`${apiUrl(config)}/${endpoint}`, payload)
23
- : await request(`${apiUrl(config)}/${endpoint}`);
19
+ ? await request(config, `${apiUrl(config)}/${endpoint}`, payload)
20
+ : await request(config, `${apiUrl(config)}/${endpoint}`);
24
21
  return response.data;
25
22
  };
26
23
  return proxify(fn, endpoint);
@@ -3,4 +3,8 @@ export type InstanceConfig = {
3
3
  production: string;
4
4
  development: string;
5
5
  };
6
+ storage?: {
7
+ strategy?: 'memo' | 'localStorage';
8
+ namespace?: string;
9
+ };
6
10
  };
@@ -0,0 +1,2 @@
1
+ import type { InstanceConfig } from './types';
2
+ export declare const apiUrl: (config: InstanceConfig) => string;
@@ -0,0 +1,8 @@
1
+ export const apiUrl = (config) => {
2
+ if (typeof config.apiUrl === 'string') {
3
+ return config.apiUrl;
4
+ }
5
+ return process.env.NODE_ENV === 'production'
6
+ ? config.apiUrl.production
7
+ : config.apiUrl.development;
8
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aeria-sdk",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/cjs/index.d.ts",