@wix/essentials 0.1.0 → 0.1.2

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/build/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import * as auth from './auth.js';
2
- import * as net from './net.js';
3
- export { auth, net };
2
+ import * as httpClient from './http-client.js';
3
+ export { auth, httpClient };
package/build/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  import * as auth from './auth.js';
2
- import * as net from './net.js';
3
- export { auth, net };
2
+ import * as httpClient from './http-client.js';
3
+ export { auth, httpClient };
@@ -0,0 +1,2 @@
1
+ import { RESTFunctionDescriptor } from '@wix/sdk-types';
2
+ export declare function elevate<T extends RESTFunctionDescriptor>(restModule: T): T;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.elevate = void 0;
4
+ const rest_modules_1 = require("@wix/sdk-runtime/rest-modules");
5
+ function elevate(restModule) {
6
+ return (0, rest_modules_1.createRESTModule)(restModule, true);
7
+ }
8
+ exports.elevate = elevate;
@@ -0,0 +1,39 @@
1
+ import { DocumentNode, GraphQLFormattedError } from 'graphql';
2
+ import { RESTFunctionDescriptor } from '@wix/sdk-types';
3
+ export declare const fetchWithAuth: typeof fetch & ((restModuleOpts: import("@wix/sdk-types").HttpClient) => typeof fetch);
4
+ export declare const graphql: (<Result, Variables>(query: string | String | DocumentNode | TypedQueryInput<Result, Variables>, variables?: Variables | undefined, opts?: {
5
+ apiVersion: string;
6
+ }) => Promise<{
7
+ data: Result;
8
+ errors?: GraphQLFormattedError[] | undefined;
9
+ }>) & RESTFunctionDescriptor<(<Result, Variables>(query: string | String | DocumentNode | TypedQueryInput<Result, Variables>, variables?: Variables | undefined, opts?: {
10
+ apiVersion: string;
11
+ }) => Promise<{
12
+ data: Result;
13
+ errors?: GraphQLFormattedError[] | undefined;
14
+ }>)>;
15
+ export type TypedQueryInput<Result = {
16
+ [key: string]: any;
17
+ }, Variables = {
18
+ [key: string]: any;
19
+ }> = {
20
+ /**
21
+ * Type to support `@graphql-typed-document-node/core`
22
+ * @internal
23
+ */
24
+ __apiType?: (variables: Variables) => Result;
25
+ /**
26
+ * Type to support `TypedQueryDocumentNode` from `graphql`
27
+ * @internal
28
+ */
29
+ __ensureTypesOfVariablesAndResultMatching?: (variables: Variables) => Result;
30
+ };
31
+ export declare class FetchErrorResponse extends Error {
32
+ readonly message: string;
33
+ readonly response: Response;
34
+ constructor(message: string, response: Response);
35
+ details(): Promise<{
36
+ details: any;
37
+ message: string;
38
+ }>;
39
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FetchErrorResponse = exports.graphql = exports.fetchWithAuth = void 0;
4
+ const rest_modules_1 = require("@wix/sdk-runtime/rest-modules");
5
+ exports.fetchWithAuth = (0, rest_modules_1.createRESTModule)((restModuleOpts) => {
6
+ return ((url, options) => restModuleOpts.fetchWithAuth(url, options));
7
+ });
8
+ exports.graphql = (0, rest_modules_1.createRESTModule)(((restModuleOpts) => {
9
+ // eslint-disable-next-line @typescript-eslint/no-shadow
10
+ return async function graphql(query, variables, opts = {
11
+ apiVersion: 'alpha',
12
+ }) {
13
+ const res = await restModuleOpts.wixAPIFetch(`/graphql/${opts.apiVersion}`, {
14
+ method: 'POST',
15
+ headers: {
16
+ 'Content-Type': 'application/json',
17
+ },
18
+ body: JSON.stringify({ query, variables }),
19
+ });
20
+ if (res.status !== 200) {
21
+ throw new FetchErrorResponse(`GraphQL request failed with status ${res.status}`, res);
22
+ }
23
+ const { data, errors } = await res.json();
24
+ return { data: data ?? {}, errors };
25
+ };
26
+ }));
27
+ class FetchErrorResponse extends Error {
28
+ message;
29
+ response;
30
+ constructor(message, response) {
31
+ super(message);
32
+ this.message = message;
33
+ this.response = response;
34
+ }
35
+ async details() {
36
+ const dataError = await this.response.json();
37
+ return errorBuilder(this.response.status, dataError?.message, dataError?.details, {
38
+ requestId: this.response.headers.get('X-Wix-Request-Id'),
39
+ details: dataError,
40
+ });
41
+ }
42
+ }
43
+ exports.FetchErrorResponse = FetchErrorResponse;
44
+ const errorBuilder = (code, description, details, data) => {
45
+ return {
46
+ details: {
47
+ ...(!details?.validationError && {
48
+ applicationError: {
49
+ description,
50
+ code,
51
+ data,
52
+ },
53
+ }),
54
+ ...details,
55
+ },
56
+ message: description,
57
+ };
58
+ };
@@ -0,0 +1,3 @@
1
+ import * as auth from './auth.js';
2
+ import * as httpClient from './http-client.js';
3
+ export { auth, httpClient };
@@ -23,8 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.net = exports.auth = void 0;
26
+ exports.httpClient = exports.auth = void 0;
27
27
  const auth = __importStar(require("./auth.js"));
28
28
  exports.auth = auth;
29
- const net = __importStar(require("./net.js"));
30
- exports.net = net;
29
+ const httpClient = __importStar(require("./http-client.js"));
30
+ exports.httpClient = httpClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/essentials",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "license": "UNLICENSED",
5
5
  "main": "cjs/build/index.js",
6
6
  "module": "build/index.mjs",
@@ -13,7 +13,8 @@
13
13
  },
14
14
  "sideEffects": false,
15
15
  "files": [
16
- "build"
16
+ "build",
17
+ "cjs"
17
18
  ],
18
19
  "publishConfig": {
19
20
  "registry": "https://registry.npmjs.org/",
@@ -68,5 +69,5 @@
68
69
  ]
69
70
  }
70
71
  },
71
- "falconPackageHash": "1b06e3c22fa1a34867fb6b2234da86c10ecec058f320dd49fcb86633"
72
+ "falconPackageHash": "865728ade2df781ba2d23f501f795d070630e7a58800bf3f928a3c59"
72
73
  }
File without changes
File without changes