js-sdk icon indicating copy to clipboard operation
js-sdk copied to clipboard

(Proposal) feat: add ResourceAbilityRequestBuilder

Open Ansonhkg opened this issue 9 months ago • 1 comments

Description

Doc is helpful, but what's even better? Having the available functions suggested to you directly in the IDE:


image

Usage:

import { ResourceAbilityRequestBuilder } from '@lit-protocol/auth-helpers';

const builder = new ResourceAbilityRequestBuilder();

builder
  .addPKPSigningRequest('*') // PKP Signing
  .addLitActionExecutionRequest('*') // Lit Action Execution
  .addAccessControlConditionSigningRequest('*') // ACC Signing
  .addAccessControlConditionDecryptionRequest('*') // ACC Decryption
  .addRateLimitIncreaseAuthRequest('*'); // RLI Authentication

const requests = builder.build();

Instead of:


import { 
  LitPKPResource, 
  LitActionResource,
  LitAccessControlConditionResource,
  LitAccessControlConditionResource,
  LitRLIResource
} from 'somewhere';
import { LitAbility } from 'somewhere-else';

const resources = [
  {
    resource: new LitPKPResource('123'),
    ability: LitAbility.PKPSigning,
  },
  {
    resource: new LitActionResource('456'),
    ability: LitAbility.LitActionExecution,
  },
  {
    resource: new LitAccessControlConditionResource('789'),
    ability: LitAbility.AccessControlConditionSigning,
  },
  {
    resource: new LitAccessControlConditionResource('abc'),
    ability: LitAbility.AccessControlConditionDecryption,
  },
  {
    resource: new LitRLIResource('def'),
    ability: LitAbility.RateLimitIncreaseAuth,
  },
]

Type of change

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [x] This change requires a documentation update

How Has This Been Tested?

Unit Test

node 'node_modules/.bin/jest' './packages/auth-helpers/src/lib/recap/resource-builder.spec.ts' -c './packages/auth-helpers/jest.config.ts' -t 'ResourceAbilityRequestBuilder'

Checklist:

  • [x] My code follows the style guidelines of this project
  • [x] I have performed a self-review of my code -[x] I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [x] My changes generate no new warnings
  • [x] I have added tests that prove my fix is effective or that my feature works
  • [x] New and existing unit tests pass locally with my changes
  • [ ] Any dependent changes have been merged and published in downstream modules

Ansonhkg avatar May 02 '24 01:05 Ansonhkg

This is cool! could we add the example in the description as a jsdoc example?

joshLong145 avatar May 02 '24 13:05 joshLong145