@@ -8,12 +8,12 @@ import {
88} from '../resources' ;
99
1010/**
11- * Lit resrouce ability request builder for creating resource ability requests.
11+ * Creates a resource ability request builder for creating resource ability requests.
1212 *
1313 * @example
14- * import { ResourceAbilityRequestBuilder } from '@lit-protocol/auth-helpers';
14+ * import { createResourceBuilder } from '@lit-protocol/auth-helpers';
1515
16- const builder = new ResourceAbilityRequestBuilder ();
16+ const builder = createResourceBuilder ();
1717
1818builder
1919 .addPKPSigningRequest('*') // PKP Signing
@@ -25,82 +25,87 @@ builder
2525const requests = builder.build();
2626
2727 */
28- export class ResourceAbilityRequestBuilder {
29- private requests : Array < {
28+ export const createResourceBuilder = ( ) => {
29+ const requests : Array < {
3030 resource : ILitResource ;
3131 ability : LIT_ABILITY_VALUES ;
3232 } > = [ ] ;
3333
34- /**
35- * Adds a PKP signing request to the builder.
36- * @param resourceId - The ID of the resource.
37- * @returns The builder instance.
38- */
39- addPKPSigningRequest ( resourceId : string ) : this {
40- this . requests . push ( {
41- resource : new LitPKPResource ( resourceId ) ,
42- ability : LIT_ABILITY . PKPSigning ,
43- } ) ;
44- return this ;
45- }
34+ return {
35+ /**
36+ * Adds a PKP signing request to the builder.
37+ * @param resourceId - The ID of the resource.
38+ * @returns The builder instance.
39+ */
40+ addPKPSigningRequest ( resourceId : string ) {
41+ requests . push ( {
42+ resource : new LitPKPResource ( resourceId ) ,
43+ ability : LIT_ABILITY . PKPSigning ,
44+ } ) ;
45+ return this ;
46+ } ,
4647
47- /**
48- * Adds a Lit action execution request to the builder.
49- * @param resourceId - The ID of the resource.
50- * @returns The builder instance.
51- */
52- addLitActionExecutionRequest ( resourceId : string ) : this {
53- this . requests . push ( {
54- resource : new LitActionResource ( resourceId ) ,
55- ability : LIT_ABILITY . LitActionExecution ,
56- } ) ;
57- return this ;
58- }
48+ /**
49+ * Adds a Lit action execution request to the builder.
50+ * @param resourceId - The ID of the resource.
51+ * @returns The builder instance.
52+ */
53+ addLitActionExecutionRequest ( resourceId : string ) {
54+ requests . push ( {
55+ resource : new LitActionResource ( resourceId ) ,
56+ ability : LIT_ABILITY . LitActionExecution ,
57+ } ) ;
58+ return this ;
59+ } ,
5960
60- /**
61- * Adds an access control condition signing request to the builder.
62- * @param resourceId - The ID of the resource.
63- * @returns The builder instance.
64- */
65- addAccessControlConditionSigningRequest ( resourceId : string ) : this {
66- this . requests . push ( {
67- resource : new LitAccessControlConditionResource ( resourceId ) ,
68- ability : LIT_ABILITY . AccessControlConditionSigning ,
69- } ) ;
70- return this ;
71- }
61+ /**
62+ * Adds an access control condition signing request to the builder.
63+ * @param resourceId - The ID of the resource.
64+ * @returns The builder instance.
65+ */
66+ addAccessControlConditionSigningRequest ( resourceId : string ) {
67+ requests . push ( {
68+ resource : new LitAccessControlConditionResource ( resourceId ) ,
69+ ability : LIT_ABILITY . AccessControlConditionSigning ,
70+ } ) ;
71+ return this ;
72+ } ,
7273
73- /**
74- * Adds an access control condition decryption request to the builder.
75- * @param resourceId - The ID of the resource.
76- * @returns The builder instance.
77- */
78- addAccessControlConditionDecryptionRequest ( resourceId : string ) : this {
79- this . requests . push ( {
80- resource : new LitAccessControlConditionResource ( resourceId ) ,
81- ability : LIT_ABILITY . AccessControlConditionDecryption ,
82- } ) ;
83- return this ;
84- }
74+ /**
75+ * Adds an access control condition decryption request to the builder.
76+ * @param resourceId - The ID of the resource.
77+ * @returns The builder instance.
78+ */
79+ addAccessControlConditionDecryptionRequest ( resourceId : string ) {
80+ requests . push ( {
81+ resource : new LitAccessControlConditionResource ( resourceId ) ,
82+ ability : LIT_ABILITY . AccessControlConditionDecryption ,
83+ } ) ;
84+ return this ;
85+ } ,
8586
86- /**
87- * Adds a rate limit increase authentication request to the builder.
88- * @param resourceId - The ID of the resource.
89- * @returns The builder instance.
90- */
91- addPaymentDelegationRequest ( resourceId : string ) : this {
92- this . requests . push ( {
93- resource : new LitPaymentDelegationResource ( resourceId ) ,
94- ability : LIT_ABILITY . PaymentDelegation ,
95- } ) ;
96- return this ;
97- }
87+ /**
88+ * Adds a rate limit increase authentication request to the builder.
89+ * @param resourceId - The ID of the resource.
90+ * @returns The builder instance.
91+ */
92+ addPaymentDelegationRequest ( resourceId : string ) {
93+ requests . push ( {
94+ resource : new LitPaymentDelegationResource ( resourceId ) ,
95+ ability : LIT_ABILITY . PaymentDelegation ,
96+ } ) ;
97+ return this ;
98+ } ,
9899
99- /**
100- * Builds the array of resource ability requests.
101- * @returns The array of resource ability requests.
102- */
103- build ( ) : Array < { resource : ILitResource ; ability : LIT_ABILITY_VALUES } > {
104- return this . requests ;
105- }
106- }
100+ /**
101+ * Return the array of resource ability requests.
102+ * @returns The array of resource ability requests.
103+ */
104+ get requests ( ) : Array < {
105+ resource : ILitResource ;
106+ ability : LIT_ABILITY_VALUES ;
107+ } > {
108+ return requests ;
109+ } ,
110+ } ;
111+ } ;
0 commit comments