@wix/essentials 0.1.5 → 0.1.7

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/auth.d.ts CHANGED
@@ -1,2 +1,21 @@
1
1
  import { RESTFunctionDescriptor } from '@wix/sdk-types';
2
2
  export declare function elevate<T extends RESTFunctionDescriptor>(restModule: T): T;
3
+ export declare const getTokenInfo: (() => Promise<{
4
+ active: boolean;
5
+ subjectType: 'APP' | 'USER' | 'MEMBER' | 'VISITOR' | 'UNKNOWN';
6
+ subjectId: string;
7
+ exp: number;
8
+ iat: number;
9
+ clientId?: string | undefined;
10
+ siteId: string;
11
+ instanceId?: string | undefined;
12
+ }>) & ((restModuleOpts: import("@wix/sdk-types").HttpClient) => () => Promise<{
13
+ active: boolean;
14
+ subjectType: 'APP' | 'USER' | 'MEMBER' | 'VISITOR' | 'UNKNOWN';
15
+ subjectId: string;
16
+ exp: number;
17
+ iat: number;
18
+ clientId?: string | undefined;
19
+ siteId: string;
20
+ instanceId?: string | undefined;
21
+ }>);
package/build/auth.js CHANGED
@@ -2,3 +2,21 @@ import { createRESTModule } from '@wix/sdk-runtime/rest-modules';
2
2
  export function elevate(restModule) {
3
3
  return createRESTModule(restModule, true);
4
4
  }
5
+ export const getTokenInfo = createRESTModule((restModuleOpts) => {
6
+ return async () => {
7
+ if (!restModuleOpts.getActiveToken) {
8
+ throw new Error('Unable to get the currently active token. Please make sure you are using an authentication strategy that supports this operation.');
9
+ }
10
+ const res = await restModuleOpts.fetchWithAuth('https://www.wixapis.com/oauth2/token-info', {
11
+ method: 'POST',
12
+ body: JSON.stringify({ token: restModuleOpts.getActiveToken() }),
13
+ headers: {
14
+ 'Content-Type': 'application/json',
15
+ },
16
+ });
17
+ if (!res.ok) {
18
+ throw new Error(`Failed to fetch token info: ${res.status} - ${res.statusText}. ${await res.text()}`);
19
+ }
20
+ return res.json();
21
+ };
22
+ });
@@ -1,2 +1,21 @@
1
1
  import { RESTFunctionDescriptor } from '@wix/sdk-types';
2
2
  export declare function elevate<T extends RESTFunctionDescriptor>(restModule: T): T;
3
+ export declare const getTokenInfo: (() => Promise<{
4
+ active: boolean;
5
+ subjectType: 'APP' | 'USER' | 'MEMBER' | 'VISITOR' | 'UNKNOWN';
6
+ subjectId: string;
7
+ exp: number;
8
+ iat: number;
9
+ clientId?: string | undefined;
10
+ siteId: string;
11
+ instanceId?: string | undefined;
12
+ }>) & ((restModuleOpts: import("@wix/sdk-types").HttpClient) => () => Promise<{
13
+ active: boolean;
14
+ subjectType: 'APP' | 'USER' | 'MEMBER' | 'VISITOR' | 'UNKNOWN';
15
+ subjectId: string;
16
+ exp: number;
17
+ iat: number;
18
+ clientId?: string | undefined;
19
+ siteId: string;
20
+ instanceId?: string | undefined;
21
+ }>);
package/cjs/build/auth.js CHANGED
@@ -1,8 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.elevate = void 0;
3
+ exports.getTokenInfo = exports.elevate = void 0;
4
4
  const rest_modules_1 = require("@wix/sdk-runtime/rest-modules");
5
5
  function elevate(restModule) {
6
6
  return (0, rest_modules_1.createRESTModule)(restModule, true);
7
7
  }
8
8
  exports.elevate = elevate;
9
+ exports.getTokenInfo = (0, rest_modules_1.createRESTModule)((restModuleOpts) => {
10
+ return async () => {
11
+ if (!restModuleOpts.getActiveToken) {
12
+ throw new Error('Unable to get the currently active token. Please make sure you are using an authentication strategy that supports this operation.');
13
+ }
14
+ const res = await restModuleOpts.fetchWithAuth('https://www.wixapis.com/oauth2/token-info', {
15
+ method: 'POST',
16
+ body: JSON.stringify({ token: restModuleOpts.getActiveToken() }),
17
+ headers: {
18
+ 'Content-Type': 'application/json',
19
+ },
20
+ });
21
+ if (!res.ok) {
22
+ throw new Error(`Failed to fetch token info: ${res.status} - ${res.statusText}. ${await res.text()}`);
23
+ }
24
+ return res.json();
25
+ };
26
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/essentials",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "license": "UNLICENSED",
5
5
  "main": "cjs/build/index.js",
6
6
  "module": "build/index.mjs",
@@ -9,7 +9,8 @@
9
9
  ".": {
10
10
  "import": "./build/index.js",
11
11
  "require": "./cjs/build/index.js"
12
- }
12
+ },
13
+ "./package.json": "./package.json"
13
14
  },
14
15
  "sideEffects": false,
15
16
  "files": [
@@ -31,8 +32,8 @@
31
32
  "*.{js,ts}": "yarn lint"
32
33
  },
33
34
  "dependencies": {
34
- "@wix/sdk-runtime": "^0.3.18",
35
- "@wix/sdk-types": "^1.10.0"
35
+ "@wix/sdk-runtime": "^0.3.19",
36
+ "@wix/sdk-types": "^1.12.0"
36
37
  },
37
38
  "optionalDependencies": {
38
39
  "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"
@@ -41,7 +42,7 @@
41
42
  "@types/is-ci": "^3.0.4",
42
43
  "@types/node": "^20.10.6",
43
44
  "@vitest/ui": "^1.5.0",
44
- "@wix/sdk": "1.12.12",
45
+ "@wix/sdk": "1.12.14",
45
46
  "eslint": "^8.56.0",
46
47
  "eslint-config-sdk": "0.0.0",
47
48
  "graphql": "^16.8.0",
@@ -69,5 +70,5 @@
69
70
  ]
70
71
  }
71
72
  },
72
- "falconPackageHash": "c248ad2e335a46e897c6582080031cfd5096bd09a2f5222d57a7cc62"
73
+ "falconPackageHash": "879e00c9e40960110f33a25e12e43513d767907868582f2fc390c476"
73
74
  }