@pakoor/n8n-nodes-instagram 0.1.4 → 0.1.5
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.
- package/dist/credentials/InstagramOAuth2Api.credentials.d.ts +8 -6
- package/dist/credentials/InstagramOAuth2Api.credentials.d.ts.map +1 -1
- package/dist/credentials/InstagramOAuth2Api.credentials.js +23 -23
- package/dist/credentials/InstagramOAuth2Api.credentials.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import type { ICredentialDataDecryptedObject, ICredentialTestRequest, ICredentialType, IDataObject, IHttpRequestHelper, INodeProperties } from 'n8n-workflow';
|
|
1
|
+
import type { IAuthenticateGeneric, ICredentialDataDecryptedObject, ICredentialTestRequest, ICredentialType, IDataObject, IHttpRequestHelper, INodeProperties } from 'n8n-workflow';
|
|
2
2
|
export declare class InstagramOAuth2Api implements ICredentialType {
|
|
3
3
|
name: string;
|
|
4
4
|
extends: string[];
|
|
5
5
|
displayName: string;
|
|
6
6
|
documentationUrl: string;
|
|
7
7
|
properties: INodeProperties[];
|
|
8
|
+
/**
|
|
9
|
+
* Authenticate requests by adding access token to query string
|
|
10
|
+
* Uses longLivedToken if available, otherwise falls back to oauthTokenData.access_token
|
|
11
|
+
*/
|
|
12
|
+
authenticate: IAuthenticateGeneric;
|
|
8
13
|
/**
|
|
9
14
|
* Pre-authentication hook that exchanges short-lived OAuth token for a long-lived token
|
|
10
|
-
* and refreshes it when near expiration.
|
|
11
|
-
*
|
|
12
|
-
* This is called by n8n before each API request when the credential has an expirable field.
|
|
13
|
-
* If this function returns new credential data, n8n will persist it to the database.
|
|
15
|
+
* and refreshes it when near expiration.
|
|
14
16
|
*/
|
|
15
17
|
preAuthentication(this: IHttpRequestHelper, credentials: ICredentialDataDecryptedObject): Promise<IDataObject>;
|
|
16
18
|
/**
|
|
17
|
-
* Test
|
|
19
|
+
* Test credentials
|
|
18
20
|
*/
|
|
19
21
|
test: ICredentialTestRequest;
|
|
20
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InstagramOAuth2Api.credentials.d.ts","sourceRoot":"","sources":["../../src/credentials/InstagramOAuth2Api.credentials.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,sBAAsB,EACtB,eAAe,EACf,WAAW,EACX,kBAAkB,EAClB,eAAe,EAChB,MAAM,cAAc,CAAC;AAEtB,qBAAa,kBAAmB,YAAW,eAAe;IACxD,IAAI,SAAwB;IAC5B,OAAO,WAAiB;IACxB,WAAW,SAA0B;IACrC,gBAAgB,SAAwE;IAExF,UAAU,EAAE,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"InstagramOAuth2Api.credentials.d.ts","sourceRoot":"","sources":["../../src/credentials/InstagramOAuth2Api.credentials.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,8BAA8B,EAC9B,sBAAsB,EACtB,eAAe,EACf,WAAW,EACX,kBAAkB,EAClB,eAAe,EAChB,MAAM,cAAc,CAAC;AAEtB,qBAAa,kBAAmB,YAAW,eAAe;IACxD,IAAI,SAAwB;IAC5B,OAAO,WAAiB;IACxB,WAAW,SAA0B;IACrC,gBAAgB,SAAwE;IAExF,UAAU,EAAE,eAAe,EAAE,CA8F3B;IAEF;;;OAGG;IACH,YAAY,EAAE,oBAAoB,CAOhC;IAEF;;;OAGG;IACG,iBAAiB,CACrB,IAAI,EAAE,kBAAkB,EACxB,WAAW,EAAE,8BAA8B,GAC1C,OAAO,CAAC,WAAW,CAAC;IAkEvB;;OAEG;IACH,IAAI,EAAE,sBAAsB,CAS1B;CACH"}
|
|
@@ -49,7 +49,7 @@ class InstagramOAuth2Api {
|
|
|
49
49
|
name: 'accountInfoNotice',
|
|
50
50
|
type: 'notice',
|
|
51
51
|
default: '',
|
|
52
|
-
description: 'After connecting your account, your Instagram Business Account details (username, ID, profile) will be automatically available.
|
|
52
|
+
description: 'After connecting your account, your Instagram Business Account details (username, ID, profile) will be automatically available. The system will automatically exchange your OAuth token for a long-lived token (60 days).',
|
|
53
53
|
},
|
|
54
54
|
{
|
|
55
55
|
displayName: 'Client ID',
|
|
@@ -79,11 +79,9 @@ class InstagramOAuth2Api {
|
|
|
79
79
|
typeOptions: { password: true },
|
|
80
80
|
default: '',
|
|
81
81
|
required: false,
|
|
82
|
-
description: 'Optional: Custom verification token for webhook setup
|
|
82
|
+
description: 'Optional: Custom verification token for webhook setup. Only needed if using Instagram Trigger node.',
|
|
83
83
|
placeholder: 'my_custom_verify_token_2024',
|
|
84
84
|
},
|
|
85
|
-
// Hidden field for long-lived token with expirable typeOption
|
|
86
|
-
// This enables n8n's preAuthentication system to persist the token
|
|
87
85
|
{
|
|
88
86
|
displayName: 'Long-Lived Token',
|
|
89
87
|
name: 'longLivedToken',
|
|
@@ -101,7 +99,19 @@ class InstagramOAuth2Api {
|
|
|
101
99
|
},
|
|
102
100
|
];
|
|
103
101
|
/**
|
|
104
|
-
*
|
|
102
|
+
* Authenticate requests by adding access token to query string
|
|
103
|
+
* Uses longLivedToken if available, otherwise falls back to oauthTokenData.access_token
|
|
104
|
+
*/
|
|
105
|
+
this.authenticate = {
|
|
106
|
+
type: 'generic',
|
|
107
|
+
properties: {
|
|
108
|
+
qs: {
|
|
109
|
+
access_token: '={{$credentials.longLivedToken || $credentials.oauthTokenData?.access_token}}',
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Test credentials
|
|
105
115
|
*/
|
|
106
116
|
this.test = {
|
|
107
117
|
request: {
|
|
@@ -116,10 +126,7 @@ class InstagramOAuth2Api {
|
|
|
116
126
|
}
|
|
117
127
|
/**
|
|
118
128
|
* Pre-authentication hook that exchanges short-lived OAuth token for a long-lived token
|
|
119
|
-
* and refreshes it when near expiration.
|
|
120
|
-
*
|
|
121
|
-
* This is called by n8n before each API request when the credential has an expirable field.
|
|
122
|
-
* If this function returns new credential data, n8n will persist it to the database.
|
|
129
|
+
* and refreshes it when near expiration.
|
|
123
130
|
*/
|
|
124
131
|
async preAuthentication(credentials) {
|
|
125
132
|
const now = Math.floor(Date.now() / 1000);
|
|
@@ -130,14 +137,12 @@ class InstagramOAuth2Api {
|
|
|
130
137
|
const shortLivedToken = oauthTokenData?.access_token;
|
|
131
138
|
// If we have a valid long-lived token that's not near expiration, no action needed
|
|
132
139
|
if (longLivedToken && tokenExpiresAt > 0) {
|
|
133
|
-
// Token is still valid with more than 7 days remaining
|
|
134
140
|
const sevenDaysInSeconds = 7 * 24 * 60 * 60;
|
|
135
141
|
if (tokenExpiresAt > now + sevenDaysInSeconds) {
|
|
136
|
-
return {};
|
|
142
|
+
return {};
|
|
137
143
|
}
|
|
138
|
-
// Token
|
|
139
|
-
|
|
140
|
-
const totalLifetime = 60 * 24 * 60 * 60; // 60 days
|
|
144
|
+
// Token near expiration, try to refresh
|
|
145
|
+
const totalLifetime = 60 * 24 * 60 * 60;
|
|
141
146
|
const tokenAge = now - (tokenExpiresAt - totalLifetime);
|
|
142
147
|
if (tokenAge >= 24 * 60 * 60) {
|
|
143
148
|
try {
|
|
@@ -154,17 +159,14 @@ class InstagramOAuth2Api {
|
|
|
154
159
|
tokenExpiresAt: now + refreshed.expires_in,
|
|
155
160
|
};
|
|
156
161
|
}
|
|
157
|
-
catch
|
|
158
|
-
// Refresh failed, but token is still valid - continue using it
|
|
159
|
-
console.warn('Instagram: Failed to refresh long-lived token, continuing with current token', error);
|
|
162
|
+
catch {
|
|
160
163
|
return {};
|
|
161
164
|
}
|
|
162
165
|
}
|
|
163
|
-
return {};
|
|
166
|
+
return {};
|
|
164
167
|
}
|
|
165
|
-
// No long-lived token
|
|
168
|
+
// No long-lived token - exchange short-lived for long-lived
|
|
166
169
|
if (!shortLivedToken) {
|
|
167
|
-
// No token available at all
|
|
168
170
|
return {};
|
|
169
171
|
}
|
|
170
172
|
try {
|
|
@@ -182,9 +184,7 @@ class InstagramOAuth2Api {
|
|
|
182
184
|
tokenExpiresAt: now + exchanged.expires_in,
|
|
183
185
|
};
|
|
184
186
|
}
|
|
185
|
-
catch
|
|
186
|
-
// Exchange failed - the short-lived token may be expired
|
|
187
|
-
console.error('Instagram: Failed to exchange OAuth token for long-lived token', error);
|
|
187
|
+
catch {
|
|
188
188
|
return {};
|
|
189
189
|
}
|
|
190
190
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InstagramOAuth2Api.credentials.js","sourceRoot":"","sources":["../../src/credentials/InstagramOAuth2Api.credentials.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"InstagramOAuth2Api.credentials.js","sourceRoot":"","sources":["../../src/credentials/InstagramOAuth2Api.credentials.ts"],"names":[],"mappings":";;;AAUA,MAAa,kBAAkB;IAA/B;QACE,SAAI,GAAG,oBAAoB,CAAC;QAC5B,YAAO,GAAG,CAAC,WAAW,CAAC,CAAC;QACxB,gBAAW,GAAG,sBAAsB,CAAC;QACrC,qBAAgB,GAAG,oEAAoE,CAAC;QAExF,eAAU,GAAsB;YAC9B;gBACE,WAAW,EAAE,YAAY;gBACzB,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,mBAAmB;aAC7B;YACD;gBACE,WAAW,EAAE,mBAAmB;gBAChC,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,2CAA2C;aACrD;YACD;gBACE,WAAW,EAAE,kBAAkB;gBAC/B,IAAI,EAAE,gBAAgB;gBACtB,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,8CAA8C;aACxD;YACD;gBACE,WAAW,EAAE,OAAO;gBACpB,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,QAAQ;gBACd,OAAO,EACL,mIAAmI;aACtI;YACD;gBACE,WAAW,EAAE,2BAA2B;gBACxC,IAAI,EAAE,qBAAqB;gBAC3B,IAAI,EAAE,QAAQ;gBACd,OAAO,E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