mp-request-handler-sdk 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 { IAMRequest } from './requestHandler';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,2 @@
1
+ // Core SDK functionality
2
+ export { IAMRequest } from './requestHandler';
@@ -0,0 +1,298 @@
1
+ type TLoginChannels = 'userqr' | 'password' | 'phoneotp' | 'numchallenge';
2
+ type TRolePayloadObj = {
3
+ role: string;
4
+ role_namespace: string;
5
+ role_uuid: string;
6
+ conditions?: {
7
+ condition_uuid: any;
8
+ operator: string;
9
+ field: string;
10
+ value: string | string[];
11
+ }[];
12
+ };
13
+ interface ICreateProjectUserPayload {
14
+ username: string;
15
+ display_name?: string;
16
+ channels: TLoginChannels[];
17
+ channel_details: {
18
+ phone_number?: string;
19
+ password?: string;
20
+ };
21
+ role?: string;
22
+ }
23
+ interface IUpdateProjectUserPayload {
24
+ user_code: string;
25
+ username?: string;
26
+ display_name?: string;
27
+ is_active?: boolean;
28
+ }
29
+ type TProjectUserListPayload = {
30
+ page: number;
31
+ per_page: number;
32
+ search: string;
33
+ is_active: boolean | undefined;
34
+ };
35
+ type TGetProjectUserDetailsPayload = {
36
+ user_code: string;
37
+ };
38
+ interface ICreateChannelPayload {
39
+ user_code: string;
40
+ channels: TLoginChannels[];
41
+ details: {
42
+ phone_number?: string;
43
+ password?: string;
44
+ };
45
+ }
46
+ interface IRemoveChannelPayload {
47
+ user_code: string;
48
+ channels: string[];
49
+ details: {
50
+ key_id?: string;
51
+ phone_number?: string;
52
+ };
53
+ }
54
+ interface IRegenerateCredPayload {
55
+ user_code: string;
56
+ channel_code: string;
57
+ whitelisted_ips?: string[];
58
+ expires_at?: string;
59
+ }
60
+ interface IManageProjectChannelsPayload {
61
+ userCode: string;
62
+ selectedChannels: TLoginChannels[];
63
+ originalChannels: TLoginChannels[];
64
+ channelDetails: {
65
+ password?: string;
66
+ phoneNumber?: string;
67
+ originalPhone?: string;
68
+ };
69
+ }
70
+ interface ICreateAccessUserPayload {
71
+ resourceNamespace: string;
72
+ resource: string;
73
+ resourceType: string;
74
+ rolesAdd?: TRolePayloadObj[];
75
+ rolesUpdate?: TRolePayloadObj[];
76
+ rolesRemove?: TRolePayloadObj[];
77
+ principalName: string;
78
+ conditions?: {
79
+ condition_uuid: any;
80
+ operator: string;
81
+ field: string;
82
+ value: string | string[];
83
+ }[];
84
+ }
85
+ interface IGetRelationPayload {
86
+ principal: string;
87
+ resource: string;
88
+ }
89
+ interface IUpdateRelationPayload {
90
+ resourceNamespace: string;
91
+ resource: string;
92
+ resourceType: string;
93
+ rolesAdd?: TRolePayloadObj[];
94
+ rolesUpdate?: TRolePayloadObj[];
95
+ rolesRemove?: TRolePayloadObj[];
96
+ principalName: string;
97
+ principal: string;
98
+ }
99
+ type TUserAccessListPayload = {
100
+ search: string;
101
+ per_page: number;
102
+ page: number;
103
+ };
104
+ type TServiceAccountCreatePayload = {
105
+ username: string;
106
+ display_name?: string;
107
+ channels: ['apijwt'];
108
+ role?: string;
109
+ channel_details: {
110
+ whitelisted_ips?: string[];
111
+ expires_at?: string;
112
+ };
113
+ };
114
+ type TGetApiUserPayload = {
115
+ user_code: string;
116
+ };
117
+ type TUpdateApiUserPayload = {
118
+ user_code: string;
119
+ display_name: string;
120
+ is_active: boolean;
121
+ };
122
+ type TGetQuotaPayload = Record<string, unknown>;
123
+ type TGetGroupPayload = {
124
+ search: string;
125
+ page: number;
126
+ limit: number;
127
+ };
128
+ type TGroupCreatePayload = {
129
+ groupName: string;
130
+ };
131
+ type TGroupUpdatePayload = {
132
+ groupCode: string;
133
+ groupName?: string;
134
+ isActive: boolean;
135
+ };
136
+ type TGroupDetailsPayload = {
137
+ groupCode: string;
138
+ };
139
+ type TAddGroupMemberPayload = {
140
+ groupCode: string;
141
+ member_name: string;
142
+ };
143
+ type TRemoveGroupMemberPayload = {
144
+ groupCode: string;
145
+ members: string[];
146
+ };
147
+ type TGetRolesPayload = {
148
+ namespace_code?: string;
149
+ search?: string;
150
+ page?: number;
151
+ per_page?: number;
152
+ };
153
+ type TGetRolePermissionsPayload = {
154
+ role_uuid: string;
155
+ page: number;
156
+ per_page: number;
157
+ search: string;
158
+ };
159
+ interface IAMActionMap {
160
+ createProjectUser: ICreateProjectUserPayload;
161
+ updateProjectUser: IUpdateProjectUserPayload;
162
+ getProjectUserList: TProjectUserListPayload;
163
+ getProjectUserDetails: TGetProjectUserDetailsPayload;
164
+ createChannel: ICreateChannelPayload;
165
+ removeChannel: IRemoveChannelPayload;
166
+ regenerateCred: IRegenerateCredPayload;
167
+ manageProjectChannels: IManageProjectChannelsPayload;
168
+ createApiUser: TServiceAccountCreatePayload;
169
+ getApiUser: TGetApiUserPayload;
170
+ updateApiUser: TUpdateApiUserPayload;
171
+ getApiUserList: TProjectUserListPayload;
172
+ getQuota: TGetQuotaPayload;
173
+ getGroupList: TGetGroupPayload;
174
+ groupCreate: TGroupCreatePayload;
175
+ updateGroup: TGroupUpdatePayload;
176
+ getGroupDetails: TGroupDetailsPayload;
177
+ removeGroupMember: TRemoveGroupMemberPayload;
178
+ addGroupMember: TAddGroupMemberPayload;
179
+ getRoles: TGetRolesPayload;
180
+ getRolePermissions: TGetRolePermissionsPayload;
181
+ getRoleHierarchy: Record<string, unknown>;
182
+ getUserAccessList: TUserAccessListPayload;
183
+ createAccessUser: ICreateAccessUserPayload;
184
+ getRelation: IGetRelationPayload;
185
+ updateRelation: IUpdateRelationPayload;
186
+ }
187
+ declare global {
188
+ interface Window {
189
+ IAMRequest?: (actiontype: string, payload: any, requestID: string, project?: string) => void;
190
+ }
191
+ }
192
+ /**
193
+ * Send an IAM request to manage users, roles, and access control
194
+ *
195
+ * @param actiontype - The type of IAM action to perform. Available actions:
196
+ * - **Project User Actions:**
197
+ * - `createProjectUser` - Create a new project user with authentication channels
198
+ * - `updateProjectUser` - Update an existing project user's information
199
+ * - `getProjectUserList` - Get a list of project users
200
+ * - `getProjectUserDetails` - Get details for a specific project user
201
+ *
202
+ * - **Channel Management Actions:**
203
+ * - `createChannel` - Create a new authentication channel for a user
204
+ * - `removeChannel` - Remove an authentication channel from a user
205
+ * - `regenerateCred` - Regenerate credentials for a user's authentication channel
206
+ * - `manageProjectChannels` - Manage multiple authentication channels at once
207
+ *
208
+ * - **Access Control Actions:**
209
+ * - `createAccessUser` - Grant access to a user by assigning roles to a resource
210
+ * - `getRelation` - Get relation details between a principal (user) and a resource
211
+ * - `updateRelation` - Update relation between principal and resource
212
+ *
213
+ * - **API User (Service Account) Actions:**
214
+ * - `createApiUser` - Create a new service account
215
+ * - `getApiUser` - Get details for a specific service account
216
+ * - `updateApiUser` - Update a service account
217
+ * - `getApiUserList` - Get a list of service accounts
218
+ *
219
+ * - **Group Management Actions:**
220
+ * - `getGroupList` - Get a list of groups
221
+ * - `groupCreate` - Create a new group
222
+ * - `updateGroup` - Update group details
223
+ * - `getGroupDetails` - Get details for a specific group
224
+ * - `addGroupMember` - Add a member to a group
225
+ * - `removeGroupMember` - Remove member(s) from a group
226
+ *
227
+ * - **Role & Permission Actions:**
228
+ * - `getRoles` - Get available roles
229
+ * - `getRolePermissions` - Get permissions for a specific role
230
+ * - `getRoleHierarchy` - Get the role hierarchy
231
+ *
232
+ * - **User Access Actions:**
233
+ * - `getUserAccessList` - Get list of user access entries
234
+ *
235
+ * - **Quota Actions:**
236
+ * - `getQuota` - Get project quota information
237
+ *
238
+ * @param payload - The payload specific to the action type. TypeScript will autocomplete the correct structure based on your selected action.
239
+ *
240
+ * @param project - Optional project code (e.g., 'PRJ1455'). When provided, will be added to request headers.
241
+ *
242
+ * @returns Promise that resolves with the API response data
243
+ *
244
+ * @example Creating a project user
245
+ * ```typescript
246
+ * const result = await IAMRequest('createProjectUser', {
247
+ * username: 'john.doe@noon.com',
248
+ * display_name: 'John Doe',
249
+ * channels: ['password'],
250
+ * channel_details: { password: 'secure123' }
251
+ * }, 'PRJ1455');
252
+ * ```
253
+ *
254
+ * @example Granting access to a user
255
+ * ```typescript
256
+ * const result = await IAMRequest('createAccessUser', {
257
+ * resourceNamespace: 'platform',
258
+ * resource: 'PRJ1455',
259
+ * resourceType: 'project',
260
+ * rolesAdd: [{
261
+ * role: 'platform.project.viewer',
262
+ * role_namespace: 'platform',
263
+ * role_uuid: 'fb7475ad-6e66-419f-930c-29e68e0cb825'
264
+ * }],
265
+ * principalName: 'user@noon.com',
266
+ * principal: 'USR12345'
267
+ * }, 'PRJ1455');
268
+ * ```
269
+ *
270
+ * @example Managing user channels
271
+ * ```typescript
272
+ * const result = await IAMRequest('manageProjectChannels', {
273
+ * userCode: 'USR12345',
274
+ * selectedChannels: ['password', 'phoneotp'],
275
+ * originalChannels: ['password'],
276
+ * channelDetails: {
277
+ * phoneNumber: '+971501234567',
278
+ * password: 'newpass123'
279
+ * }
280
+ * }, 'PRJ1455');
281
+ * ```
282
+ *
283
+ * @example Getting role information
284
+ * ```typescript
285
+ * const result = await IAMRequest('getRoles', {
286
+ * namespace_code: 'platform',
287
+ * search: 'viewer',
288
+ * page: 1,
289
+ * per_page: 20
290
+ * }, 'PRJ1455');
291
+ * ```
292
+ *
293
+ * @see Partner Platform documentation: https://docs.noon.partners
294
+ * @see For detailed payload structures, TypeScript autocomplete will guide you based on your selected action
295
+ */
296
+ export declare const IAMRequest: <K extends keyof IAMActionMap>(actiontype: K, payload: IAMActionMap[K], project?: string) => Promise<unknown>;
297
+ export default IAMRequest;
298
+ //# sourceMappingURL=requestHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requestHandler.d.ts","sourceRoot":"","sources":["../../src/core/requestHandler.ts"],"names":[],"mappings":"AAOA,KAAK,cAAc,GAAG,QAAQ,GAAG,UAAU,GAAG,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IACtC,iBAAiB,EAAE,yBAAyB,CAAC;IAC7C,cAAc,EAAE,sBAAsB,CAAC;IAGvC,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,kBAAkB,EAAE,0BAA0B,CAAC;IAC/C,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAG1C,iBAAiB,EAAE,sBAAsB,CAAC;IAC1C,gBAAgB,EAAE,wBAAwB,CAAC;IAC3C,WAAW,EAAE,mBAAmB,CAAC;IACjC,cAAc,EAAE,sBAAsB,CAAC;CAE1C;AAID,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QACZ,UAAU,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;KAChG;CACJ;AAwFD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuGG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,MAAM,YAAY,EACnD,YAAY,CAAC,EACb,SAAS,YAAY,CAAC,CAAC,CAAC,EACxB,UAAU,MAAM,KACjB,OAAO,CAAC,OAAO,CAA4D,CAAC;AAE/E,eAAe,UAAU,CAAC"}
@@ -0,0 +1,182 @@
1
+ /* eslint-disable camelcase */
2
+ // Type definitions for IAM actions and payloads
3
+ // @noon/iam-request-handler package
4
+ class IAMRequestHandler {
5
+ constructor() {
6
+ this.pendingRequests = new Map();
7
+ this.isReady = false;
8
+ this.init();
9
+ }
10
+ init() {
11
+ // Listen for responses
12
+ window.addEventListener('IAMResponse', (event) => {
13
+ const customEvent = event;
14
+ const { data, error, requestID, success } = customEvent.detail;
15
+ const pending = this.pendingRequests.get(requestID);
16
+ if (pending) {
17
+ this.pendingRequests.delete(requestID);
18
+ if (success) {
19
+ pending.resolve(data);
20
+ }
21
+ else {
22
+ pending.reject(new Error(error || 'IAM request failed'));
23
+ }
24
+ }
25
+ });
26
+ // Check if window.IAMRequest is available
27
+ this.checkReady();
28
+ }
29
+ checkReady() {
30
+ if (typeof window.IAMRequest === 'function') {
31
+ this.isReady = true;
32
+ this.flushQueue();
33
+ }
34
+ else {
35
+ // Poll until IAMRequest is available
36
+ setTimeout(() => this.checkReady(), 100);
37
+ }
38
+ }
39
+ flushQueue() {
40
+ // All requests in pendingRequests are already sent via request()
41
+ // This just marks as ready for future requests
42
+ }
43
+ request(actiontype, payload, project) {
44
+ return new Promise((resolve, reject) => {
45
+ // Generate unique request ID
46
+ const requestID = `iam_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
47
+ // Store the promise handlers
48
+ this.pendingRequests.set(requestID, { resolve, reject });
49
+ // Set timeout
50
+ setTimeout(() => {
51
+ if (this.pendingRequests.has(requestID)) {
52
+ this.pendingRequests.delete(requestID);
53
+ reject(new Error('IAM request timeout'));
54
+ }
55
+ }, 10000);
56
+ // Send request immediately if ready, otherwise wait
57
+ if (this.isReady && window.IAMRequest) {
58
+ window.IAMRequest(actiontype, payload, requestID, project);
59
+ }
60
+ else {
61
+ // Queue and send when ready
62
+ const checkAndSend = () => {
63
+ if (this.isReady && window.IAMRequest) {
64
+ window.IAMRequest(actiontype, payload, requestID, project);
65
+ }
66
+ else {
67
+ setTimeout(checkAndSend, 100);
68
+ }
69
+ };
70
+ checkAndSend();
71
+ }
72
+ });
73
+ }
74
+ }
75
+ // Export for client apps
76
+ const iamRequestHandler = new IAMRequestHandler();
77
+ /**
78
+ * Send an IAM request to manage users, roles, and access control
79
+ *
80
+ * @param actiontype - The type of IAM action to perform. Available actions:
81
+ * - **Project User Actions:**
82
+ * - `createProjectUser` - Create a new project user with authentication channels
83
+ * - `updateProjectUser` - Update an existing project user's information
84
+ * - `getProjectUserList` - Get a list of project users
85
+ * - `getProjectUserDetails` - Get details for a specific project user
86
+ *
87
+ * - **Channel Management Actions:**
88
+ * - `createChannel` - Create a new authentication channel for a user
89
+ * - `removeChannel` - Remove an authentication channel from a user
90
+ * - `regenerateCred` - Regenerate credentials for a user's authentication channel
91
+ * - `manageProjectChannels` - Manage multiple authentication channels at once
92
+ *
93
+ * - **Access Control Actions:**
94
+ * - `createAccessUser` - Grant access to a user by assigning roles to a resource
95
+ * - `getRelation` - Get relation details between a principal (user) and a resource
96
+ * - `updateRelation` - Update relation between principal and resource
97
+ *
98
+ * - **API User (Service Account) Actions:**
99
+ * - `createApiUser` - Create a new service account
100
+ * - `getApiUser` - Get details for a specific service account
101
+ * - `updateApiUser` - Update a service account
102
+ * - `getApiUserList` - Get a list of service accounts
103
+ *
104
+ * - **Group Management Actions:**
105
+ * - `getGroupList` - Get a list of groups
106
+ * - `groupCreate` - Create a new group
107
+ * - `updateGroup` - Update group details
108
+ * - `getGroupDetails` - Get details for a specific group
109
+ * - `addGroupMember` - Add a member to a group
110
+ * - `removeGroupMember` - Remove member(s) from a group
111
+ *
112
+ * - **Role & Permission Actions:**
113
+ * - `getRoles` - Get available roles
114
+ * - `getRolePermissions` - Get permissions for a specific role
115
+ * - `getRoleHierarchy` - Get the role hierarchy
116
+ *
117
+ * - **User Access Actions:**
118
+ * - `getUserAccessList` - Get list of user access entries
119
+ *
120
+ * - **Quota Actions:**
121
+ * - `getQuota` - Get project quota information
122
+ *
123
+ * @param payload - The payload specific to the action type. TypeScript will autocomplete the correct structure based on your selected action.
124
+ *
125
+ * @param project - Optional project code (e.g., 'PRJ1455'). When provided, will be added to request headers.
126
+ *
127
+ * @returns Promise that resolves with the API response data
128
+ *
129
+ * @example Creating a project user
130
+ * ```typescript
131
+ * const result = await IAMRequest('createProjectUser', {
132
+ * username: 'john.doe@noon.com',
133
+ * display_name: 'John Doe',
134
+ * channels: ['password'],
135
+ * channel_details: { password: 'secure123' }
136
+ * }, 'PRJ1455');
137
+ * ```
138
+ *
139
+ * @example Granting access to a user
140
+ * ```typescript
141
+ * const result = await IAMRequest('createAccessUser', {
142
+ * resourceNamespace: 'platform',
143
+ * resource: 'PRJ1455',
144
+ * resourceType: 'project',
145
+ * rolesAdd: [{
146
+ * role: 'platform.project.viewer',
147
+ * role_namespace: 'platform',
148
+ * role_uuid: 'fb7475ad-6e66-419f-930c-29e68e0cb825'
149
+ * }],
150
+ * principalName: 'user@noon.com',
151
+ * principal: 'USR12345'
152
+ * }, 'PRJ1455');
153
+ * ```
154
+ *
155
+ * @example Managing user channels
156
+ * ```typescript
157
+ * const result = await IAMRequest('manageProjectChannels', {
158
+ * userCode: 'USR12345',
159
+ * selectedChannels: ['password', 'phoneotp'],
160
+ * originalChannels: ['password'],
161
+ * channelDetails: {
162
+ * phoneNumber: '+971501234567',
163
+ * password: 'newpass123'
164
+ * }
165
+ * }, 'PRJ1455');
166
+ * ```
167
+ *
168
+ * @example Getting role information
169
+ * ```typescript
170
+ * const result = await IAMRequest('getRoles', {
171
+ * namespace_code: 'platform',
172
+ * search: 'viewer',
173
+ * page: 1,
174
+ * per_page: 20
175
+ * }, 'PRJ1455');
176
+ * ```
177
+ *
178
+ * @see Partner Platform documentation: https://docs.noon.partners
179
+ * @see For detailed payload structures, TypeScript autocomplete will guide you based on your selected action
180
+ */
181
+ export const IAMRequest = (actiontype, payload, project) => iamRequestHandler.request(actiontype, payload, project);
182
+ export default IAMRequest;
@@ -0,0 +1,2 @@
1
+ export { useRequestHandler } from './useRequestHandler';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,2 @@
1
+ // React hooks for SDK
2
+ export { useRequestHandler } from './useRequestHandler';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * React hook for using IAMRequest
3
+ */
4
+ export declare function useRequestHandler(): {
5
+ request: (action: string, payload: any) => Promise<unknown>;
6
+ loading: boolean;
7
+ error: Error | null;
8
+ };
9
+ //# sourceMappingURL=useRequestHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRequestHandler.d.ts","sourceRoot":"","sources":["../../src/hooks/useRequestHandler.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,iBAAiB;sBAKV,MAAM,WAAW,GAAG;;;EAmB1C"}
@@ -0,0 +1,26 @@
1
+ import { useCallback, useState } from 'react';
2
+ import { IAMRequest } from '../core/requestHandler';
3
+ /**
4
+ * React hook for using IAMRequest
5
+ */
6
+ export function useRequestHandler() {
7
+ const [loading, setLoading] = useState(false);
8
+ const [error, setError] = useState(null);
9
+ const request = useCallback(async (action, payload) => {
10
+ setLoading(true);
11
+ setError(null);
12
+ try {
13
+ const response = await IAMRequest(action, payload);
14
+ return response;
15
+ }
16
+ catch (err) {
17
+ const error = err instanceof Error ? err : new Error(String(err));
18
+ setError(error);
19
+ throw error;
20
+ }
21
+ finally {
22
+ setLoading(false);
23
+ }
24
+ }, []);
25
+ return { request, loading, error };
26
+ }
@@ -0,0 +1,5 @@
1
+ export * from './core';
2
+ export * from './utils';
3
+ export * from './types';
4
+ export * from './hooks';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ // Main entry point for the SDK
2
+ export * from './core';
3
+ export * from './utils';
4
+ export * from './types';
5
+ export * from './hooks';
@@ -0,0 +1,11 @@
1
+ export interface RequestConfig {
2
+ baseURL?: string;
3
+ timeout?: number;
4
+ headers?: Record<string, string>;
5
+ }
6
+ export interface ApiResponse<T> {
7
+ data: T;
8
+ status: number;
9
+ message?: string;
10
+ }
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,aAAa;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,WAAW,CAAC,CAAC;IAC1B,IAAI,EAAE,CAAC,CAAC;IACR,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export { parseResponse } from './parser';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,2 @@
1
+ // Utility functions
2
+ export { parseResponse } from './parser';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Parse API response
3
+ */
4
+ export declare function parseResponse<T>(data: any): T;
5
+ //# sourceMappingURL=parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/utils/parser.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,CAE7C"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Parse API response
3
+ */
4
+ export function parseResponse(data) {
5
+ return data;
6
+ }
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "mp-request-handler-sdk",
3
+ "version": "0.1.0",
4
+ "description": "Frontend SDK for request handling",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "dev": "tsc --watch",
13
+ "test": "jest",
14
+ "lint": "eslint src --ext .ts,.tsx",
15
+ "pack": "yarn build && npm pack --pack-destination ../../dist",
16
+ "pack:tgz": "yarn build && mkdir -p ../../dist && npm pack --pack-destination ../../dist"
17
+ },
18
+ "keywords": [
19
+ "sdk",
20
+ "request-handler",
21
+ "iam",
22
+ "identity"
23
+ ],
24
+ "author": "",
25
+ "license": "MIT",
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "dependencies": {
30
+ "axios": "^1.5.0"
31
+ },
32
+ "devDependencies": {
33
+ "@types/jest": "^29.5.0",
34
+ "@types/node": "^18.0.0",
35
+ "@types/react": "^18.2.21",
36
+ "@typescript-eslint/eslint-plugin": "^5.0.0",
37
+ "@typescript-eslint/parser": "^5.0.0",
38
+ "eslint": "^8.0.0",
39
+ "jest": "^29.5.0",
40
+ "typescript": "^5.0.0"
41
+ },
42
+ "peerDependencies": {
43
+ "react": "^18.2.0"
44
+ },
45
+ "peerDependenciesMeta": {
46
+ "react": {
47
+ "optional": true
48
+ }
49
+ }
50
+ }