@wix/web-methods 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
+ export { webMethod } from './web-method.js';
2
+ export { Permissions } from './permissions.js';
package/build/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { webMethod } from './web-method.js';
2
+ export { Permissions } from './permissions.js';
@@ -0,0 +1,21 @@
1
+ export declare enum Roles {
2
+ SITE_OWNER = "siteOwner",
3
+ SITE_MEMBER = "siteMember",
4
+ ANONYMOUS = "anonymous"
5
+ }
6
+ export interface Permission {
7
+ allowedRoles: Roles[];
8
+ }
9
+ export declare const WEB_METHOD_OPTIONS_PROPERTY_NAME = "options";
10
+ export declare const WEB_METHOD_PERMISSIONS_PROPERTY_NAME = "permission";
11
+ export declare const Permissions: {
12
+ Admin: {
13
+ allowedRoles: Roles.SITE_OWNER[];
14
+ };
15
+ SiteMember: {
16
+ allowedRoles: (Roles.SITE_OWNER | Roles.SITE_MEMBER)[];
17
+ };
18
+ Anyone: {
19
+ allowedRoles: Roles[];
20
+ };
21
+ };
@@ -0,0 +1,20 @@
1
+ export var Roles;
2
+ (function (Roles) {
3
+ Roles["SITE_OWNER"] = "siteOwner";
4
+ Roles["SITE_MEMBER"] = "siteMember";
5
+ Roles["ANONYMOUS"] = "anonymous";
6
+ })(Roles || (Roles = {}));
7
+ var PermissionOptions;
8
+ (function (PermissionOptions) {
9
+ PermissionOptions["Admin"] = "Admin";
10
+ PermissionOptions["SiteMember"] = "SiteMember";
11
+ PermissionOptions["Anyone"] = "Anyone";
12
+ })(PermissionOptions || (PermissionOptions = {}));
13
+ const { SITE_OWNER, SITE_MEMBER, ANONYMOUS } = Roles;
14
+ export const WEB_METHOD_OPTIONS_PROPERTY_NAME = 'options';
15
+ export const WEB_METHOD_PERMISSIONS_PROPERTY_NAME = 'permission';
16
+ export const Permissions = {
17
+ Admin: { allowedRoles: [SITE_OWNER] },
18
+ SiteMember: { allowedRoles: [SITE_OWNER, SITE_MEMBER] },
19
+ Anyone: { allowedRoles: [SITE_OWNER, SITE_MEMBER, ANONYMOUS] },
20
+ };
@@ -0,0 +1,8 @@
1
+ export type Handler<Args extends unknown[], Return> = (...args: Args) => Return;
2
+ export interface CacheOptions {
3
+ tags: string[];
4
+ ttl?: number;
5
+ }
6
+ export interface WebMethodOptions {
7
+ cache?: CacheOptions;
8
+ }
package/build/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { Permission } from './permissions.js';
2
+ import { Handler, WebMethodOptions } from './types.js';
3
+ export declare function webMethod<Args extends any[], Return>(permission: Permission, method: Handler<Args, Return>, options?: WebMethodOptions): Handler<Args, Promise<Awaited<Return>>>;
@@ -0,0 +1,12 @@
1
+ import { WEB_METHOD_OPTIONS_PROPERTY_NAME, WEB_METHOD_PERMISSIONS_PROPERTY_NAME, } from './permissions.js';
2
+ // https://dev.wix.com/docs/velo/api-reference/wix-web-module/introduction
3
+ export function webMethod(permission, method, options) {
4
+ const webMethodEnrichment = {
5
+ [WEB_METHOD_PERMISSIONS_PROPERTY_NAME]: permission,
6
+ ...(options && { [WEB_METHOD_OPTIONS_PROPERTY_NAME]: options }),
7
+ };
8
+ const enrichedWebMethod = Object.assign(method, webMethodEnrichment);
9
+ // the return type of `webMethod` doesn't match its return type so that
10
+ // developers who call this would get the correct types
11
+ return enrichedWebMethod;
12
+ }
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@wix/web-methods",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": "./build/index.js",
7
+ "./package.json": "./package.json"
8
+ },
9
+ "sideEffects": false,
10
+ "files": [
11
+ "build"
12
+ ],
13
+ "publishConfig": {
14
+ "registry": "https://registry.npmjs.org/",
15
+ "access": "public"
16
+ },
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "test": ":",
20
+ "lint": "eslint --max-warnings=0 .",
21
+ "lint:fix": "eslint --max-warnings=0 . --fix",
22
+ "typecheck": "tsc --noEmit"
23
+ },
24
+ "lint-staged": {
25
+ "*.{js,ts}": "yarn lint"
26
+ },
27
+ "devDependencies": {
28
+ "eslint": "^8.57.1",
29
+ "eslint-config-sdk": "0.0.0",
30
+ "typescript": "^5.7.2"
31
+ },
32
+ "eslintConfig": {
33
+ "extends": "sdk"
34
+ },
35
+ "wix": {
36
+ "artifact": {
37
+ "groupId": "com.wixpress",
38
+ "artifactId": "web-methods"
39
+ },
40
+ "validations": {
41
+ "source": [
42
+ "lint"
43
+ ],
44
+ "postDependenciesBuild": [
45
+ "typecheck"
46
+ ]
47
+ }
48
+ },
49
+ "falconPackageHash": "f7f210eef43674d6221d872892796140d99ffdf03b83e8e70b25df23"
50
+ }