@wix/essentials 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,2 @@
1
+ import { RESTFunctionDescriptor } from '@wix/sdk-types';
2
+ export declare function elevate<T extends RESTFunctionDescriptor>(restModule: T): T;
package/build/auth.js ADDED
@@ -0,0 +1,4 @@
1
+ import { createRESTModule } from '@wix/sdk-runtime/rest-modules';
2
+ export function elevate(restModule) {
3
+ return createRESTModule(restModule, true);
4
+ }
@@ -0,0 +1,3 @@
1
+ import * as auth from './auth.js';
2
+ import * as net from './net.js';
3
+ export { auth, net };
package/build/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import * as auth from './auth.js';
2
+ import * as net from './net.js';
3
+ export { auth, net };
package/build/net.d.ts ADDED
@@ -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
+ }
package/build/net.js ADDED
@@ -0,0 +1,54 @@
1
+ import { createRESTModule } from '@wix/sdk-runtime/rest-modules';
2
+ export const fetchWithAuth = createRESTModule((restModuleOpts) => {
3
+ return ((url, options) => restModuleOpts.fetchWithAuth(url, options));
4
+ });
5
+ export const graphql = createRESTModule(((restModuleOpts) => {
6
+ // eslint-disable-next-line @typescript-eslint/no-shadow
7
+ return async function graphql(query, variables, opts = {
8
+ apiVersion: 'alpha',
9
+ }) {
10
+ const res = await restModuleOpts.wixAPIFetch(`/graphql/${opts.apiVersion}`, {
11
+ method: 'POST',
12
+ headers: {
13
+ 'Content-Type': 'application/json',
14
+ },
15
+ body: JSON.stringify({ query, variables }),
16
+ });
17
+ if (res.status !== 200) {
18
+ throw new FetchErrorResponse(`GraphQL request failed with status ${res.status}`, res);
19
+ }
20
+ const { data, errors } = await res.json();
21
+ return { data: data ?? {}, errors };
22
+ };
23
+ }));
24
+ export class FetchErrorResponse extends Error {
25
+ message;
26
+ response;
27
+ constructor(message, response) {
28
+ super(message);
29
+ this.message = message;
30
+ this.response = response;
31
+ }
32
+ async details() {
33
+ const dataError = await this.response.json();
34
+ return errorBuilder(this.response.status, dataError?.message, dataError?.details, {
35
+ requestId: this.response.headers.get('X-Wix-Request-Id'),
36
+ details: dataError,
37
+ });
38
+ }
39
+ }
40
+ const errorBuilder = (code, description, details, data) => {
41
+ return {
42
+ details: {
43
+ ...(!details?.validationError && {
44
+ applicationError: {
45
+ description,
46
+ code,
47
+ data,
48
+ },
49
+ }),
50
+ ...details,
51
+ },
52
+ message: description,
53
+ };
54
+ };
@@ -0,0 +1,30 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.net = exports.auth = void 0;
27
+ const auth = __importStar(require("./auth.js"));
28
+ exports.auth = auth;
29
+ const net = __importStar(require("./net.js"));
30
+ exports.net = net;
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@wix/essentials",
3
+ "version": "0.1.0",
4
+ "license": "UNLICENSED",
5
+ "main": "cjs/build/index.js",
6
+ "module": "build/index.mjs",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./build/index.js",
11
+ "require": "./cjs/build/index.js"
12
+ }
13
+ },
14
+ "sideEffects": false,
15
+ "files": [
16
+ "build"
17
+ ],
18
+ "publishConfig": {
19
+ "registry": "https://registry.npmjs.org/",
20
+ "access": "public"
21
+ },
22
+ "scripts": {
23
+ "build": "tsc && tsc --project tsconfig.cjs.json",
24
+ "test": ":",
25
+ "lint": "eslint --max-warnings=0 .",
26
+ "lint:fix": "eslint --max-warnings=0 . --fix",
27
+ "typecheck": "tsc --noEmit"
28
+ },
29
+ "lint-staged": {
30
+ "*.{js,ts}": "yarn lint"
31
+ },
32
+ "dependencies": {
33
+ "@wix/sdk-runtime": "^0.3.16",
34
+ "@wix/sdk-types": "^1.9.3"
35
+ },
36
+ "optionalDependencies": {
37
+ "graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
38
+ },
39
+ "devDependencies": {
40
+ "@types/is-ci": "^3.0.4",
41
+ "@types/node": "^20.10.6",
42
+ "@vitest/ui": "^1.5.0",
43
+ "@wix/sdk-runtime": "0.3.16",
44
+ "eslint": "^8.56.0",
45
+ "eslint-config-sdk": "0.0.0",
46
+ "graphql": "^16.8.0",
47
+ "is-ci": "^3.0.1",
48
+ "jsdom": "^22.1.0",
49
+ "msw": "^2.0.12",
50
+ "typescript": "^5.3.3",
51
+ "vitest": "^1.5.0",
52
+ "vitest-teamcity-reporter": "^0.3.0"
53
+ },
54
+ "eslintConfig": {
55
+ "extends": "sdk"
56
+ },
57
+ "wix": {
58
+ "artifact": {
59
+ "groupId": "com.wixpress",
60
+ "artifactId": "sdk-essentials"
61
+ },
62
+ "validations": {
63
+ "source": [
64
+ "lint"
65
+ ],
66
+ "postDependenciesBuild": [
67
+ "typecheck"
68
+ ]
69
+ }
70
+ },
71
+ "falconPackageHash": "1b06e3c22fa1a34867fb6b2234da86c10ecec058f320dd49fcb86633"
72
+ }