aeria-sdk 0.0.209 → 0.0.210

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/auth.js CHANGED
@@ -1,21 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.signout = exports.authenticate = void 0;
4
- const types_1 = require("@aeriajs/types");
5
- const http_js_1 = require("./http.js");
6
- const utils_js_1 = require("./utils.js");
7
- const storage_js_1 = require("./storage.js");
8
- const authenticate = (config) => async (payload) => {
9
- const response = await (0, http_js_1.request)(config, `${(0, utils_js_1.publicUrl)(config)}/user/authenticate`, payload);
1
+ import { Result } from '@aeriajs/types';
2
+ import { request } from './http.js';
3
+ import { publicUrl } from './utils.js';
4
+ import { getStorage } from './storage.js';
5
+ export const authenticate = (config) => async (payload) => {
6
+ const response = await request(config, `${publicUrl(config)}/user/authenticate`, payload);
10
7
  const { error, result } = response.data;
11
8
  if (result) {
12
- (0, storage_js_1.getStorage)(config).set('auth', result);
13
- return types_1.Result.result(result);
9
+ getStorage(config).set('auth', result);
10
+ return Result.result(result);
14
11
  }
15
- return types_1.Result.error(error);
12
+ return Result.error(error);
16
13
  };
17
- exports.authenticate = authenticate;
18
- const signout = (config) => async () => {
19
- (0, storage_js_1.getStorage)(config).remove('auth');
14
+ export const signout = (config) => async () => {
15
+ getStorage(config).remove('auth');
20
16
  };
21
- exports.signout = signout;
package/dist/cli.js CHANGED
@@ -1,9 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const node_util_1 = require("node:util");
4
- const mirror_js_1 = require("./mirror.js");
5
- const config_js_1 = require("./config.js");
6
- const { values: opts } = (0, node_util_1.parseArgs)({
1
+ import { parseArgs } from 'node:util';
2
+ import { mirrorRemotely } from './mirror.js';
3
+ import { getConfig } from './config.js';
4
+ const { values: opts } = parseArgs({
7
5
  options: {
8
6
  dev: {
9
7
  type: 'boolean',
@@ -12,10 +10,10 @@ const { values: opts } = (0, node_util_1.parseArgs)({
12
10
  },
13
11
  });
14
12
  const main = async () => {
15
- const config = await (0, config_js_1.getConfig)();
13
+ const config = await getConfig();
16
14
  if (opts.dev) {
17
15
  config.environment = 'development';
18
16
  }
19
- (0, mirror_js_1.mirrorRemotely)(config);
17
+ mirrorRemotely(config);
20
18
  };
21
19
  main();
package/dist/config.js CHANGED
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getConfig = void 0;
4
- const path = require("node:path");
5
- const fs = require("node:fs/promises");
6
- const getConfig = async () => {
1
+ import * as path from 'node:path';
2
+ import * as fs from 'node:fs/promises';
3
+ export const getConfig = async () => {
7
4
  const { aeriaSdk } = JSON.parse(await fs.readFile(path.join(process.cwd(), 'package.json'), {
8
5
  encoding: 'utf8',
9
6
  }));
@@ -12,4 +9,3 @@ const getConfig = async () => {
12
9
  }
13
10
  return aeriaSdk;
14
11
  };
15
- exports.getConfig = getConfig;
package/dist/constants.js CHANGED
@@ -1,4 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_STORAGE_NAMESPACE = void 0;
4
- exports.DEFAULT_STORAGE_NAMESPACE = 'aeria';
1
+ export const DEFAULT_STORAGE_NAMESPACE = 'aeria';
package/dist/http.js CHANGED
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.request = void 0;
4
- const common_1 = require("@aeriajs/common");
5
- const storage_js_1 = require("./storage.js");
1
+ import { request as originalRequest } from '@aeriajs/common';
2
+ import { getStorage } from './storage.js';
6
3
  const sdkRequestTransformer = (config, next) => (context) => {
7
4
  const params = Object.assign({
8
5
  headers: {},
9
6
  }, context.params);
10
- const auth = (0, storage_js_1.getStorage)(config).get('auth');
7
+ const auth = getStorage(config).get('auth');
11
8
  if (auth?.token && !params.headers.authorization) {
12
9
  switch (auth.token.type) {
13
10
  case 'bearer': {
@@ -19,7 +16,7 @@ const sdkRequestTransformer = (config, next) => (context) => {
19
16
  context.params = params;
20
17
  return next(context);
21
18
  };
22
- const request = (config, url, payload, _requestConfig) => {
19
+ export const request = (config, url, payload, _requestConfig) => {
23
20
  const requestConfig = Object.assign({}, _requestConfig);
24
21
  const { requestTransformer: userDefinedRequestTransformer } = requestConfig;
25
22
  if (userDefinedRequestTransformer) {
@@ -32,6 +29,5 @@ const request = (config, url, payload, _requestConfig) => {
32
29
  return sdkRequestTransformer(config, next)(context);
33
30
  };
34
31
  }
35
- return (0, common_1.request)(url, payload, requestConfig);
32
+ return originalRequest(url, payload, requestConfig);
36
33
  };
37
- exports.request = request;
package/dist/index.js CHANGED
@@ -1,29 +1,10 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.throwIfError = exports.Result = void 0;
18
- var types_1 = require("@aeriajs/types");
19
- Object.defineProperty(exports, "Result", { enumerable: true, get: function () { return types_1.Result; } });
20
- var common_1 = require("@aeriajs/common");
21
- Object.defineProperty(exports, "throwIfError", { enumerable: true, get: function () { return common_1.throwIfError; } });
22
- __exportStar(require("./auth.js"), exports);
23
- __exportStar(require("./instance.js"), exports);
24
- __exportStar(require("./constants.js"), exports);
25
- __exportStar(require("./http.js"), exports);
26
- __exportStar(require("./runtime.js"), exports);
27
- __exportStar(require("./storage.js"), exports);
28
- __exportStar(require("./types.js"), exports);
29
- __exportStar(require("./utils.js"), exports);
1
+ export { Result, } from '@aeriajs/types';
2
+ export { throwIfError, } from '@aeriajs/common';
3
+ export * from './auth.js';
4
+ export * from './instance.js';
5
+ export * from './constants.js';
6
+ export * from './http.js';
7
+ export * from './runtime.js';
8
+ export * from './storage.js';
9
+ export * from './types.js';
10
+ export * from './utils.js';
package/dist/instance.js CHANGED
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createInstance = exports.call = exports.interceptors = void 0;
4
- const http_js_1 = require("./http.js");
5
- const utils_js_1 = require("./utils.js");
6
- exports.interceptors = {};
1
+ import { request } from './http.js';
2
+ import { publicUrl } from './utils.js';
3
+ export const interceptors = {};
7
4
  const proxify = (config, _target, context, bearerToken, segment) => {
8
5
  return new Proxy(_target, {
9
6
  get: (target, key) => {
@@ -16,7 +13,7 @@ const proxify = (config, _target, context, bearerToken, segment) => {
16
13
  const nextSegment = segment
17
14
  ? `${segment}/${key}`
18
15
  : key;
19
- const fn = (0, exports.call)()(key, uri, {
16
+ const fn = call()(key, uri, {
20
17
  config,
21
18
  context,
22
19
  bearerToken,
@@ -25,11 +22,11 @@ const proxify = (config, _target, context, bearerToken, segment) => {
25
22
  },
26
23
  });
27
24
  };
28
- const call = () => (method, route, params) => {
25
+ export const call = () => (method, route, params) => {
29
26
  const { context = {
30
- interceptors: exports.interceptors,
27
+ interceptors,
31
28
  }, } = params;
32
- const { request: requestTransformer = exports.interceptors.request, response: responseTransformer = exports.interceptors.response, } = context.interceptors;
29
+ const { request: requestTransformer = interceptors.request, response: responseTransformer = interceptors.response, } = context.interceptors;
33
30
  const fn = async (payload) => {
34
31
  const requestConfig = {
35
32
  requestTransformer,
@@ -49,18 +46,16 @@ const call = () => (method, route, params) => {
49
46
  if (params.bearerToken) {
50
47
  requestConfig.params.headers.authorization = `Bearer ${params.bearerToken}`;
51
48
  }
52
- const { data } = await (0, http_js_1.request)(params.config, `${(0, utils_js_1.publicUrl)(params.config)}${route}`, payload, requestConfig);
49
+ const { data } = await request(params.config, `${publicUrl(params.config)}${route}`, payload, requestConfig);
53
50
  return data;
54
51
  };
55
52
  return fn;
56
53
  };
57
- exports.call = call;
58
- const createInstance = (config, instanceContext = {
59
- interceptors: exports.interceptors,
54
+ export const createInstance = (config, instanceContext = {
55
+ interceptors,
60
56
  }) => {
61
57
  const fn = (bearerToken) => {
62
58
  return proxify(config, {}, instanceContext, bearerToken);
63
59
  };
64
60
  return proxify(config, fn, instanceContext);
65
61
  };
66
- exports.createInstance = createInstance;
package/dist/mirror.d.ts CHANGED
@@ -3,8 +3,7 @@ type MirrorObject = {
3
3
  descriptions: unknown;
4
4
  router?: unknown;
5
5
  };
6
- export declare const runtimeCjs: (config: InstanceConfig) => string;
7
- export declare const runtimeEsm: (config: InstanceConfig) => string;
6
+ export declare const runtimeContent: (config: InstanceConfig) => string;
8
7
  export declare const writeMirrorFiles: (mirror: MirrorObject, config: InstanceConfig) => Promise<void>;
9
8
  export declare const mirrorRemotely: (config: InstanceConfig) => Promise<void>;
10
9
  export {};
package/dist/mirror.js CHANGED
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mirrorRemotely = exports.writeMirrorFiles = exports.runtimeEsm = exports.runtimeCjs = void 0;
4
- const common_1 = require("@aeriajs/common");
5
- const path = require("node:path");
6
- const promises_1 = require("node:fs/promises");
7
- const module_1 = require("module");
8
- const instance_js_1 = require("./instance.js");
9
- const utils_js_1 = require("./utils.js");
1
+ import { deserialize } from '@aeriajs/common';
2
+ import * as path from 'node:path';
3
+ import { writeFile } from 'node:fs/promises';
4
+ import { createRequire } from 'module';
5
+ import { createInstance } from './instance.js';
6
+ import { publicUrl } from './utils.js';
10
7
  const DTS_FILENAME = 'aeria-sdk.d.ts';
11
8
  const mirrorDts = (mirrorObj, config) => {
12
9
  const { descriptions, router, } = mirrorObj;
@@ -95,35 +92,23 @@ declare module 'aeria-sdk' {
95
92
  }
96
93
  \n`;
97
94
  };
98
- const runtimeCjs = (config) => `const config = ${JSON.stringify(config)}
99
- const aeria = require('./instance.js').createInstance(config)
100
- exports.instanceConfig = config
101
- exports.url = '${(0, utils_js_1.publicUrl)(config)}'
102
- exports.aeria = aeria
103
- exports.storage = require('./storage.js').getStorage(config)
104
- exports.upload = require('./upload.js').uploader(config)
105
- exports.default = aeria
106
- \n`;
107
- exports.runtimeCjs = runtimeCjs;
108
- const runtimeEsm = (config) => `import { createInstance } from './instance.mjs'
109
- import { getStorage } from './storage.mjs'
110
- import { uploader } from './upload.mjs'
95
+ export const runtimeContent = (config) => `import { createInstance } from './instance.js'
96
+ import { getStorage } from './storage.js'
97
+ import { uploader } from './upload.js'
111
98
  export const instanceConfig = ${JSON.stringify(config)}
112
- export const url = '${(0, utils_js_1.publicUrl)(config)}'
99
+ export const url = '${publicUrl(config)}'
113
100
  export const aeria = createInstance(instanceConfig)
114
101
  export const storage = getStorage(instanceConfig)
115
102
  export const upload = uploader(instanceConfig)
116
103
  export default aeria
117
104
  \n`;
118
- exports.runtimeEsm = runtimeEsm;
119
- const writeMirrorFiles = async (mirror, config) => {
105
+ export const writeMirrorFiles = async (mirror, config) => {
120
106
  const mirrorPaths = config.mirrorPaths || ['.aeria']
121
107
  .map((mirrorPath) => path.join(process.cwd(), mirrorPath));
122
108
  const dts = mirrorDts(mirror, config);
123
- const cjs = (0, exports.runtimeCjs)(config);
124
- const esm = (0, exports.runtimeEsm)(config);
109
+ const js = runtimeContent(config);
125
110
  for (const mirrorPath of mirrorPaths) {
126
- const syntheticRequire = (0, module_1.createRequire)(path.join(path.dirname(path.resolve(mirrorPath)), 'node_modules'));
111
+ const syntheticRequire = createRequire(path.join(path.dirname(path.resolve(mirrorPath)), 'node_modules'));
127
112
  let resolvedPath;
128
113
  try {
129
114
  resolvedPath = syntheticRequire.resolve('aeria-sdk');
@@ -133,24 +118,18 @@ const writeMirrorFiles = async (mirror, config) => {
133
118
  continue;
134
119
  }
135
120
  const runtimeBase = path.dirname(resolvedPath);
136
- await (0, promises_1.writeFile)(path.join(mirrorPath, DTS_FILENAME), dts);
121
+ await writeFile(path.join(mirrorPath, DTS_FILENAME), dts);
137
122
  // this array join must be used, otherwise the .js will be transformed by the transform-import-extensions script
138
- await (0, promises_1.writeFile)(path.join(runtimeBase, [
123
+ await writeFile(path.join(runtimeBase, [
139
124
  'runtime',
140
125
  'js',
141
- ].join('.')), cjs);
142
- await (0, promises_1.writeFile)(path.join(runtimeBase, [
143
- 'runtime',
144
- 'mjs',
145
- ].join('.')), esm);
126
+ ].join('.')), js);
146
127
  }
147
128
  };
148
- exports.writeMirrorFiles = writeMirrorFiles;
149
- const mirrorRemotely = async (config) => {
150
- const aeria = (0, instance_js_1.createInstance)(config);
151
- const mirror = (0, common_1.deserialize)(await aeria().describe.POST({
129
+ export const mirrorRemotely = async (config) => {
130
+ const aeria = createInstance(config);
131
+ const mirror = deserialize(await aeria().describe.POST({
152
132
  router: true,
153
133
  }));
154
- return (0, exports.writeMirrorFiles)(mirror, config);
134
+ return writeMirrorFiles(mirror, config);
155
135
  };
156
- exports.mirrorRemotely = mirrorRemotely;
package/dist/runtime.js CHANGED
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.storage = exports.upload = exports.aeria = exports.url = exports.instanceConfig = void 0;
4
- exports.instanceConfig = {};
5
- exports.url = '';
6
- exports.aeria = {};
7
- exports.upload = {};
8
- exports.storage = {};
9
- exports.default = exports.aeria;
1
+ export const instanceConfig = {};
2
+ export const url = '';
3
+ export const aeria = {};
4
+ export const upload = {};
5
+ export const storage = {};
6
+ export default aeria;
10
7
  throw new Error("Runtime files weren't generated. Run the \"aeria-sdk\" script first.");
package/dist/storage.js CHANGED
@@ -1,14 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getStorage = exports.storageKey = exports.storageMemo = void 0;
4
- const constants_js_1 = require("./constants.js");
5
- exports.storageMemo = {};
6
- const storageKey = (key, config) => {
7
- const namespace = config.storage?.namespace || constants_js_1.DEFAULT_STORAGE_NAMESPACE;
1
+ import { DEFAULT_STORAGE_NAMESPACE } from './constants.js';
2
+ export const storageMemo = {};
3
+ export const storageKey = (key, config) => {
4
+ const namespace = config.storage?.namespace || DEFAULT_STORAGE_NAMESPACE;
8
5
  return `${namespace}:${key}`;
9
6
  };
10
- exports.storageKey = storageKey;
11
- const getStorage = (config) => {
7
+ export const getStorage = (config) => {
12
8
  const strategy = !config.storage?.strategy
13
9
  ? 'none'
14
10
  : config.storage.strategy === 'localStorage' && !('localStorage' in globalThis)
@@ -17,9 +13,9 @@ const getStorage = (config) => {
17
13
  function get(key) {
18
14
  switch (strategy) {
19
15
  case 'memo':
20
- return exports.storageMemo[key] || null;
16
+ return storageMemo[key] || null;
21
17
  case 'localStorage':
22
- const value = localStorage.getItem((0, exports.storageKey)(key, config));
18
+ const value = localStorage.getItem(storageKey(key, config));
23
19
  return value
24
20
  ? JSON.parse(value)
25
21
  : null;
@@ -30,23 +26,22 @@ const getStorage = (config) => {
30
26
  remove: (key) => {
31
27
  switch (strategy) {
32
28
  case 'memo':
33
- delete exports.storageMemo[key];
29
+ delete storageMemo[key];
34
30
  break;
35
31
  case 'localStorage':
36
- localStorage.removeItem((0, exports.storageKey)(key, config));
32
+ localStorage.removeItem(storageKey(key, config));
37
33
  break;
38
34
  }
39
35
  },
40
36
  set: (key, value) => {
41
37
  switch (strategy) {
42
38
  case 'memo':
43
- exports.storageMemo[key] = value;
39
+ storageMemo[key] = value;
44
40
  break;
45
41
  case 'localStorage':
46
42
  const serialized = JSON.stringify(value);
47
- return localStorage.setItem((0, exports.storageKey)(key, config), serialized);
43
+ return localStorage.setItem(storageKey(key, config), serialized);
48
44
  }
49
45
  },
50
46
  };
51
47
  };
52
- exports.getStorage = getStorage;
package/dist/types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/dist/upload.js CHANGED
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uploader = void 0;
4
- const http_js_1 = require("./http.js");
5
- const utils_js_1 = require("./utils.js");
6
- const uploader = (config) => (bearerToken) => async (collectionName, params) => {
1
+ import { request } from './http.js';
2
+ import { publicUrl } from './utils.js';
3
+ export const uploader = (config) => (bearerToken) => async (collectionName, params) => {
7
4
  const urlParams = {
8
5
  name: params.name,
9
6
  format: params.format || 'raw',
10
7
  };
11
- const url = new URL((0, utils_js_1.publicUrl)(config));
8
+ const url = new URL(publicUrl(config));
12
9
  url.pathname += `/${collectionName}/upload`;
13
10
  for (const [paramName, paramValue] of Object.entries(urlParams)) {
14
11
  url.searchParams.set(paramName, paramValue);
@@ -26,7 +23,6 @@ const uploader = (config) => (bearerToken) => async (collectionName, params) =>
26
23
  if (bearerToken) {
27
24
  requestConfig.params.headers.authorization = `Bearer ${bearerToken}`;
28
25
  }
29
- const response = await (0, http_js_1.request)(config, url.toString(), params.content, requestConfig);
26
+ const response = await request(config, url.toString(), params.content, requestConfig);
30
27
  return response.data;
31
28
  };
32
- exports.uploader = uploader;
package/dist/utils.js CHANGED
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.publicUrl = void 0;
4
- const publicUrl = (config) => {
1
+ export const publicUrl = (config) => {
5
2
  if (typeof config.publicUrl === 'string') {
6
3
  return config.publicUrl;
7
4
  }
@@ -9,4 +6,3 @@ const publicUrl = (config) => {
9
6
  ? config.publicUrl.development
10
7
  : config.publicUrl.production;
11
8
  };
12
- exports.publicUrl = publicUrl;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "aeria-sdk",
3
- "version": "0.0.209",
3
+ "type": "module",
4
+ "version": "0.0.210",
4
5
  "description": "",
5
6
  "main": "dist/index.js",
6
- "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
8
8
  "keywords": [],
9
9
  "author": "",
@@ -21,30 +21,24 @@
21
21
  "exports": {
22
22
  ".": {
23
23
  "types": "./dist/index.d.ts",
24
- "webpack": "./dist/index.js",
25
- "import": "./dist/index.mjs",
26
- "require": "./dist/index.js"
24
+ "default": "./dist/index.js"
27
25
  },
28
26
  "./next": "./dist/index.js",
29
27
  "./config": {
30
28
  "types": "./dist/config.d.ts",
31
- "import": "./dist/config.mjs",
32
- "require": "./dist/config.js"
29
+ "default": "./dist/config.js"
33
30
  },
34
31
  "./http": {
35
32
  "types": "./dist/http.d.ts",
36
- "import": "./dist/http.mjs",
37
- "require": "./dist/http.js"
33
+ "default": "./dist/http.js"
38
34
  },
39
35
  "./mirror": {
40
36
  "types": "./dist/mirror.d.ts",
41
- "import": "./dist/mirror.mjs",
42
- "require": "./dist/mirror.js"
37
+ "default": "./dist/mirror.js"
43
38
  },
44
39
  "./topLevel": {
45
40
  "types": "./dist/topLevel.d.ts",
46
- "import": "./dist/topLevel.mjs",
47
- "require": "./dist/topLevel.js"
41
+ "default": "./dist/topLevel.js"
48
42
  }
49
43
  },
50
44
  "devDependencies": {
@@ -52,16 +46,13 @@
52
46
  "@aeriajs/types": "link:../types"
53
47
  },
54
48
  "peerDependencies": {
55
- "@aeriajs/common": "^0.0.157",
56
- "@aeriajs/types": "^0.0.135"
49
+ "@aeriajs/common": "^0.0.158",
50
+ "@aeriajs/types": "^0.0.136"
57
51
  },
58
52
  "scripts": {
59
53
  "test": "echo skipping",
60
54
  "lint": "eslint .",
61
55
  "lint:fix": "eslint . --fix",
62
- "build": "pnpm build:cjs && pnpm build:esm",
63
- "build:cjs": "tsc",
64
- "build:esm": "esbuild './src/**/*.ts' --outdir=dist --out-extension:.js=.mjs && pnpm build:esm-transform",
65
- "build:esm-transform": "pnpm -w esm-transform $PWD/dist"
56
+ "build": "tsc"
66
57
  }
67
58
  }
package/dist/auth.mjs DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
- import { Result } from "@aeriajs/types";
3
- import { request } from "./http.mjs";
4
- import { publicUrl } from "./utils.mjs";
5
- import { getStorage } from "./storage.mjs";
6
- export const authenticate = (config) => async (payload) => {
7
- const response = await request(config, `${publicUrl(config)}/user/authenticate`, payload);
8
- const { error, result } = response.data;
9
- if (result) {
10
- getStorage(config).set("auth", result);
11
- return Result.result(result);
12
- }
13
- return Result.error(error);
14
- };
15
- export const signout = (config) => async () => {
16
- getStorage(config).remove("auth");
17
- };
package/dist/cli.mjs DELETED
@@ -1,20 +0,0 @@
1
- "use strict";
2
- import { parseArgs } from "node:util";
3
- import { mirrorRemotely } from "./mirror.mjs";
4
- import { getConfig } from "./config.mjs";
5
- const { values: opts } = parseArgs({
6
- options: {
7
- dev: {
8
- type: "boolean",
9
- short: "d"
10
- }
11
- }
12
- });
13
- const main = async () => {
14
- const config = await getConfig();
15
- if (opts.dev) {
16
- config.environment = "development";
17
- }
18
- mirrorRemotely(config);
19
- };
20
- main();
package/dist/config.mjs DELETED
@@ -1,12 +0,0 @@
1
- "use strict";
2
- import * as path from "node:path";
3
- import * as fs from "node:fs/promises";
4
- export const getConfig = async () => {
5
- const { aeriaSdk } = JSON.parse(await fs.readFile(path.join(process.cwd(), "package.json"), {
6
- encoding: "utf8"
7
- }));
8
- if (typeof aeriaSdk !== "object" || !aeriaSdk) {
9
- throw new Error("aeriaSdk is absent in package.json");
10
- }
11
- return aeriaSdk;
12
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- export const DEFAULT_STORAGE_NAMESPACE = "aeria";
package/dist/http.mjs DELETED
@@ -1,33 +0,0 @@
1
- "use strict";
2
- import { request as originalRequest } from "@aeriajs/common";
3
- import { getStorage } from "./storage.mjs";
4
- const sdkRequestTransformer = (config, next) => (context) => {
5
- const params = Object.assign({
6
- headers: {}
7
- }, context.params);
8
- const auth = getStorage(config).get("auth");
9
- if (auth?.token && !params.headers.authorization) {
10
- switch (auth.token.type) {
11
- case "bearer": {
12
- params.headers.authorization = `Bearer ${auth.token.content}`;
13
- break;
14
- }
15
- }
16
- }
17
- context.params = params;
18
- return next(context);
19
- };
20
- export const request = (config, url, payload, _requestConfig) => {
21
- const requestConfig = Object.assign({}, _requestConfig);
22
- const { requestTransformer: userDefinedRequestTransformer } = requestConfig;
23
- if (userDefinedRequestTransformer) {
24
- requestConfig.requestTransformer = (context, next) => {
25
- return userDefinedRequestTransformer(context, sdkRequestTransformer(config, next));
26
- };
27
- } else {
28
- requestConfig.requestTransformer = (context, next) => {
29
- return sdkRequestTransformer(config, next)(context);
30
- };
31
- }
32
- return originalRequest(url, payload, requestConfig);
33
- };
package/dist/index.mjs DELETED
@@ -1,15 +0,0 @@
1
- "use strict";
2
- export {
3
- Result
4
- } from "@aeriajs/types";
5
- export {
6
- throwIfError
7
- } from "@aeriajs/common";
8
- export * from "./auth.mjs";
9
- export * from "./instance.mjs";
10
- export * from "./constants.mjs";
11
- export * from "./http.mjs";
12
- export * from "./runtime.mjs";
13
- export * from "./storage.mjs";
14
- export * from "./types.mjs";
15
- export * from "./utils.mjs";
package/dist/instance.mjs DELETED
@@ -1,63 +0,0 @@
1
- "use strict";
2
- import { request } from "./http.mjs";
3
- import { publicUrl } from "./utils.mjs";
4
- export const interceptors = {};
5
- const proxify = (config, _target, context, bearerToken, segment) => {
6
- return new Proxy(_target, {
7
- get: (target, key) => {
8
- if (typeof key === "symbol") {
9
- return target[key];
10
- }
11
- const uri = segment ? `/${segment}` : `/${key}`;
12
- const nextSegment = segment ? `${segment}/${key}` : key;
13
- const fn = call()(key, uri, {
14
- config,
15
- context,
16
- bearerToken
17
- });
18
- return proxify(config, fn, context, bearerToken, nextSegment);
19
- }
20
- });
21
- };
22
- export const call = () => (method, route, params) => {
23
- const {
24
- context = {
25
- interceptors
26
- }
27
- } = params;
28
- const {
29
- request: requestTransformer = interceptors.request,
30
- response: responseTransformer = interceptors.response
31
- } = context.interceptors;
32
- const fn = async (payload) => {
33
- const requestConfig = {
34
- requestTransformer,
35
- responseTransformer,
36
- params: {
37
- method,
38
- headers: {}
39
- }
40
- };
41
- if (method !== "GET" && method !== "HEAD") {
42
- if (payload) {
43
- requestConfig.params.headers = {
44
- "content-type": "application/json"
45
- };
46
- }
47
- }
48
- if (params.bearerToken) {
49
- requestConfig.params.headers.authorization = `Bearer ${params.bearerToken}`;
50
- }
51
- const { data } = await request(params.config, `${publicUrl(params.config)}${route}`, payload, requestConfig);
52
- return data;
53
- };
54
- return fn;
55
- };
56
- export const createInstance = (config, instanceContext = {
57
- interceptors
58
- }) => {
59
- const fn = (bearerToken) => {
60
- return proxify(config, {}, instanceContext, bearerToken);
61
- };
62
- return proxify(config, fn, instanceContext);
63
- };
package/dist/mirror.mjs DELETED
@@ -1,154 +0,0 @@
1
- "use strict";
2
- import { deserialize } from "@aeriajs/common";
3
- import * as path from "node:path";
4
- import { writeFile } from "node:fs/promises";
5
- import { createRequire } from "module";
6
- import { createInstance } from "./instance.mjs";
7
- import { publicUrl } from "./utils.mjs";
8
- const DTS_FILENAME = "aeria-sdk.d.ts";
9
- const mirrorDts = (mirrorObj, config) => {
10
- const {
11
- descriptions,
12
- router
13
- } = mirrorObj;
14
- return `import type {
15
- InferProperty,
16
- InferProperties,
17
- SchemaWithId,
18
- PackReferences,
19
- RequestMethod,
20
- CollectionFunctionsSDK
21
-
22
- } from '@aeriajs/types'
23
-
24
- declare type MirrorDescriptions = ${JSON.stringify(descriptions, null, 2)}
25
-
26
-
27
- declare type MirrorApiSchema = ${JSON.stringify(router, null, 2)}
28
-
29
-
30
- ${config.integrated ? "" : `declare global {
31
- type Collections = {
32
- [K in keyof MirrorDescriptions]: {
33
- item: SchemaWithId<MirrorDescriptions[K], { useObjectIds: false }>
34
- }
35
- }
36
- }
37
- `}
38
- declare module 'aeria-sdk' {
39
- import { AeriaInstance, MakeEndpoint, ApiSchema } from 'aeria-sdk'
40
-
41
- type UnionToIntersection<T> = (T extends unknown ? ((x: T) => 0) : never) extends ((x: infer R) => 0)
42
- ? R
43
- : never
44
-
45
- type InferEndpoints<TApiSchema extends ApiSchema, TRoute extends keyof TApiSchema & string> = {
46
- [Method in keyof TApiSchema[TRoute]]: Method extends RequestMethod
47
- ? TApiSchema[TRoute][Method] extends infer Contract
48
- ? Contract extends
49
- | { response: infer RouteResponse }
50
- | { payload: infer RoutePayload }
51
- | { query: infer RoutePayload }
52
- ? MakeEndpoint<
53
- TRoute,
54
- Method,
55
- InferProperties<RouteResponse, { useObjectIds: false }>,
56
- RoutePayload extends {}
57
- ? PackReferences<InferProperty<RoutePayload, { useObjectIds: false }>>
58
- : undefined
59
- >
60
- : MakeEndpoint<TRoute, Method>
61
- : never
62
- : never
63
- } extends infer Methods
64
- ? Methods[keyof Methods]
65
- : never
66
-
67
- export type Api = {
68
- [Route in keyof MirrorApiSchema]: Route extends \`/\${infer Coll}/\${infer Fn}\`
69
- ? Coll extends keyof Collections
70
- ? Fn extends keyof CollectionFunctionsSDK
71
- ? Record<Coll, Record<
72
- Fn, {
73
- POST: CollectionFunctionsSDK<MirrorDescriptions[Coll]>[Fn]
74
- }
75
- >>
76
- : InferEndpoints<MirrorApiSchema, Route>
77
- : InferEndpoints<MirrorApiSchema, Route>
78
- : InferEndpoints<MirrorApiSchema, Route>
79
- } extends infer Api
80
- ? UnionToIntersection<Api[keyof Api]>
81
- : never
82
-
83
- type TopLevelAeria =
84
- & ((bearerToken?: string) => AeriaInstance & Api)
85
- & AeriaInstance & Api
86
-
87
- const topLevelAeria: TopLevelAeria
88
-
89
- export {
90
- MirrorDescriptions,
91
- MirrorApiSchema,
92
- }
93
-
94
- export const url: string
95
- export const aeria: TopLevelAeria
96
- export default topLevelAeria
97
- }
98
-
99
- `;
100
- };
101
- export const runtimeCjs = (config) => `const config = ${JSON.stringify(config)}
102
- const aeria = require('./instance.mjs').createInstance(config)
103
- exports.instanceConfig = config
104
- exports.url = '${publicUrl(config)}'
105
- exports.aeria = aeria
106
- exports.storage = require('./storage.mjs').getStorage(config)
107
- exports.upload = require('./upload.mjs').uploader(config)
108
- exports.default = aeria
109
-
110
- `;
111
- export const runtimeEsm = (config) => `import { createInstance } from './instance.mjs'
112
- import { getStorage } from './storage.mjs'
113
- import { uploader } from './upload.mjs'
114
- export const instanceConfig = ${JSON.stringify(config)}
115
- export const url = '${publicUrl(config)}'
116
- export const aeria = createInstance(instanceConfig)
117
- export const storage = getStorage(instanceConfig)
118
- export const upload = uploader(instanceConfig)
119
- export default aeria
120
-
121
- `;
122
- export const writeMirrorFiles = async (mirror, config) => {
123
- const mirrorPaths = config.mirrorPaths || [".aeria"].map((mirrorPath) => path.join(process.cwd(), mirrorPath));
124
- const dts = mirrorDts(mirror, config);
125
- const cjs = runtimeCjs(config);
126
- const esm = runtimeEsm(config);
127
- for (const mirrorPath of mirrorPaths) {
128
- const syntheticRequire = createRequire(path.join(path.dirname(path.resolve(mirrorPath)), "node_modules"));
129
- let resolvedPath;
130
- try {
131
- resolvedPath = syntheticRequire.resolve("aeria-sdk");
132
- } catch (err) {
133
- console.warn(`couldn't locate node_modules in "${mirrorPath}"`);
134
- continue;
135
- }
136
- const runtimeBase = path.dirname(resolvedPath);
137
- await writeFile(path.join(mirrorPath, DTS_FILENAME), dts);
138
- await writeFile(path.join(runtimeBase, [
139
- "runtime",
140
- "js"
141
- ].join(".")), cjs);
142
- await writeFile(path.join(runtimeBase, [
143
- "runtime",
144
- "mjs"
145
- ].join(".")), esm);
146
- }
147
- };
148
- export const mirrorRemotely = async (config) => {
149
- const aeria = createInstance(config);
150
- const mirror = deserialize(await aeria().describe.POST({
151
- router: true
152
- }));
153
- return writeMirrorFiles(mirror, config);
154
- };
package/dist/runtime.mjs DELETED
@@ -1,8 +0,0 @@
1
- "use strict";
2
- export const instanceConfig = {};
3
- export const url = "";
4
- export const aeria = {};
5
- export const upload = {};
6
- export const storage = {};
7
- export default aeria;
8
- throw new Error(`Runtime files weren't generated. Run the "aeria-sdk" script first.`);
package/dist/storage.mjs DELETED
@@ -1,42 +0,0 @@
1
- "use strict";
2
- import { DEFAULT_STORAGE_NAMESPACE } from "./constants.mjs";
3
- export const storageMemo = {};
4
- export const storageKey = (key, config) => {
5
- const namespace = config.storage?.namespace || DEFAULT_STORAGE_NAMESPACE;
6
- return `${namespace}:${key}`;
7
- };
8
- export const getStorage = (config) => {
9
- const strategy = !config.storage?.strategy ? "none" : config.storage.strategy === "localStorage" && !("localStorage" in globalThis) ? "none" : config.storage.strategy;
10
- function get(key) {
11
- switch (strategy) {
12
- case "memo":
13
- return storageMemo[key] || null;
14
- case "localStorage":
15
- const value = localStorage.getItem(storageKey(key, config));
16
- return value ? JSON.parse(value) : null;
17
- }
18
- }
19
- return {
20
- get,
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
- const serialized = JSON.stringify(value);
38
- return localStorage.setItem(storageKey(key, config), serialized);
39
- }
40
- }
41
- };
42
- };
package/dist/types.mjs DELETED
@@ -1 +0,0 @@
1
- "use strict";
package/dist/upload.mjs DELETED
@@ -1,34 +0,0 @@
1
- "use strict";
2
- import { request } from "./http.mjs";
3
- import { publicUrl } from "./utils.mjs";
4
- export const uploader = (config) => (bearerToken) => async (collectionName, params) => {
5
- const urlParams = {
6
- name: params.name,
7
- format: params.format || "raw"
8
- };
9
- const url = new URL(publicUrl(config));
10
- url.pathname += `/${collectionName}/upload`;
11
- for (const [paramName, paramValue] of Object.entries(urlParams)) {
12
- url.searchParams.set(paramName, paramValue);
13
- }
14
- const headers = {
15
- "x-stream-request": "1",
16
- "content-type": params.type
17
- };
18
- const requestConfig = {
19
- params: {
20
- method: "POST",
21
- headers
22
- }
23
- };
24
- if (bearerToken) {
25
- requestConfig.params.headers.authorization = `Bearer ${bearerToken}`;
26
- }
27
- const response = await request(
28
- config,
29
- url.toString(),
30
- params.content,
31
- requestConfig
32
- );
33
- return response.data;
34
- };
package/dist/utils.mjs DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
- export const publicUrl = (config) => {
3
- if (typeof config.publicUrl === "string") {
4
- return config.publicUrl;
5
- }
6
- return config.environment === "development" ? config.publicUrl.development : config.publicUrl.production;
7
- };