@aravinthan_p/appnest-app-sdk-utils 1.0.2 → 1.0.3

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.
@@ -11,9 +11,9 @@ This document is the **single source of truth** for the Appnest custom SDK funct
11
11
  ## Import
12
12
 
13
13
  ```javascript
14
- const AppnestFunctions = require('appnest-app-sdk-utils');
14
+ const { AppnestFunctions } = require('appnest-app-sdk-utils');
15
15
  // or from path:
16
- // const AppnestFunctions = require('<path-to-sdk>/appnestFunctions');
16
+ // const { AppnestFunctions } = require('<path-to-sdk>/appnestFunctions');
17
17
 
18
18
  const { $db, $file, $http, $next, $schedule, getTraceId } = AppnestFunctions;
19
19
  ```
@@ -38,6 +38,8 @@ const { $http } = require('appnest-app-sdk-utils');
38
38
 
39
39
  ## Installation params (iparams) for API calls
40
40
 
41
+ **Rule — required for all API calls:** Any value that comes from app configuration (installation params / iparams) and is used in a `$http` request **must** be expressed using the replace syntax `<%=iparams.<param_key>%>` in **url**, **headers**, **body**, or **query**. Do not hardcode these values or read them at runtime; the AppNest framework replaces the placeholders at request time.
42
+
41
43
  When making an API call through `$http`, if the developer needs to use an iparam-specific key/value from their manifest, they must define it under **installation_params** in the manifest.
42
44
 
43
45
  ### Defining iparams in the manifest
@@ -73,6 +75,14 @@ Reference iparams in the request **url**, **headers**, or **body** using the rep
73
75
 
74
76
  The same replacement syntax (`<%=iparams.<param_key>%>`) can be used wherever dynamic values from iparams are required in the request configuration.
75
77
 
78
+ ### For AI / code generation
79
+
80
+ When generating code that uses `$http.request`:
81
+
82
+ - **Always** use `<%=iparams.<param_key>%>` for any value that comes from installation params (API keys, base URLs, tenant IDs, etc.) in `url`, `headers`, `body`, or `query`. Never substitute a variable or literal for an iparam value in the request config.
83
+ - **Never** hardcode API keys, base URLs, or other config that is (or could be) defined in the app manifest; use the replace syntax so the framework can inject the correct value per installation.
84
+ - If the manifest defines an iparam (e.g. `api_key`, `api_url`), every `$http` usage that needs that value **must** reference it as `<%=iparams.<param_key>%>` in the request object.
85
+
76
86
  ### Using access_token in headers
77
87
 
78
88
  To send the platform’s **access_token** in the request (e.g. for OAuth or API auth), use the replace syntax in **headers**. The AppNest framework will replace `<%=user_oauth.access_token%>` with the actual token at runtime.
@@ -81,12 +91,12 @@ To send the platform’s **access_token** in the request (e.g. for OAuth or API
81
91
 
82
92
  ```javascript
83
93
  headers: {
84
- Authorization: "Bearer <%=access_token%>",
94
+ Authorization: "Bearer <%=user_oauth.access_token%>",
85
95
  "Content-Type": "application/json"
86
96
  }
87
97
  ```
88
98
 
89
- Use this in your `$http.request` call; the framework replaces `<%=access_token%>` before the request is sent.
99
+ Use this in your `$http.request` call; the framework replaces `<%=user_oauth.access_token%>` before the request is sent.
90
100
 
91
101
  ---
92
102
 
@@ -138,7 +148,7 @@ const result = await $http.request({
138
148
  url: 'https://api.example.com/v1/me',
139
149
  method: 'GET',
140
150
  headers: {
141
- Authorization: "Bearer <%=access_token%>",
151
+ Authorization: "Bearer <%=user_oauth.access_token%>",
142
152
  "Content-Type": "application/json"
143
153
  },
144
154
  body: {},
@@ -6,8 +6,10 @@ const validateRequestData = ({ url, query, method, headers, body }) => {
6
6
  if (!url) throw new Error("url is required");
7
7
  if (typeof url !== "string") throw new Error("url must be a string");
8
8
  if (url.length === 0) throw new Error("url must be a non-empty string");
9
- if (!url.startsWith("https://") && !url.startsWith("http://")) {
10
- throw new Error("url must start with https:// or http://");
9
+ if(!url.includes("<%=")) {
10
+ if (!url.startsWith("https://") && !url.startsWith("http://")) {
11
+ throw new Error("url must start with https:// or http://");
12
+ }
11
13
  }
12
14
  if (url.length > 2048) throw new Error("url must be less than 2048 characters");
13
15
  if (!method) throw new Error("method is required");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aravinthan_p/appnest-app-sdk-utils",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "axios": "^1.2.1",