addie-js 0.0.6 → 0.0.7

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.
Files changed (2) hide show
  1. package/addie.js +206 -5
  2. package/package.json +2 -2
package/addie.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import sessionless from 'sessionless-node';
2
- import fetch from 'node-fetch';
3
2
 
4
3
  const get = async (url) => {
5
4
  return await fetch(url);
@@ -29,9 +28,34 @@ const _delete = async (url, payload) => {
29
28
  });
30
29
  };
31
30
 
31
+ const patch = async (url, payload) => {
32
+ return await fetch(url, {
33
+ method: 'patch',
34
+ body: JSON.stringify(payload),
35
+ headers: {'Content-Type': 'application/json'}
36
+ });
37
+ };
38
+
32
39
  const addie = {
33
40
  baseURL: 'https://dev.addie.allyabase.com/',
34
41
 
42
+ /**
43
+ * Configure the Addie client for different environments
44
+ * @param {Object} config - Configuration options
45
+ * @param {string} config.baseURL - Direct base URL (e.g., 'http://127.0.0.1:5116/')
46
+ * @param {string} config.wikiBaseURL - Wiki proxy base URL (e.g., 'http://127.0.0.1:5124')
47
+ * Will construct URL as: {wikiBaseURL}/plugin/allyabase/addie/
48
+ */
49
+ configure: (config) => {
50
+ if (config.wikiBaseURL) {
51
+ // Wiki proxy mode: route through wiki plugin
52
+ addie.baseURL = `${config.wikiBaseURL.replace(/\/$/, '')}/plugin/allyabase/addie/`;
53
+ } else if (config.baseURL) {
54
+ // Direct mode: use base URL as-is
55
+ addie.baseURL = config.baseURL.endsWith('/') ? config.baseURL : config.baseURL + '/';
56
+ }
57
+ },
58
+
35
59
  createUser: async (saveKeys, getKeys) => {
36
60
  const keys = (await getKeys()) || (await sessionless.generateKeys(saveKeys, getKeys))
37
61
  sessionless.getKeys = getKeys;
@@ -40,11 +64,13 @@ const addie = {
40
64
  timestamp: new Date().getTime() + '',
41
65
  pubKey: keys.pubKey
42
66
  };
67
+ console.log('signing', payload.timestamp + payload.pubKey);
43
68
 
44
69
  payload.signature = await sessionless.sign(payload.timestamp + payload.pubKey);
45
70
 
46
71
  const res = await put(`${addie.baseURL}user/create`, payload);
47
72
  const user = await res.json();
73
+ console.log('response from addie', user);
48
74
  const uuid = user.uuid;
49
75
 
50
76
  return uuid;
@@ -63,8 +89,24 @@ const addie = {
63
89
  return user;
64
90
  },
65
91
 
66
- addProcessorAccount: async (uuid, processorPayload) => {
67
- return 'unimplemented';
92
+ addProcessorAccount: async (uuid, processor, country, name, email) => {
93
+ const timestamp = new Date().getTime() + '';
94
+ const message = timestamp + uuid + name + email;
95
+ const signature = await sessionless.sign(message);
96
+
97
+ const payload = {
98
+ timestamp,
99
+ country,
100
+ name,
101
+ email,
102
+ signature
103
+ };
104
+
105
+ const url = `${addie.baseURL}user/${uuid}/processor/${processor}`;
106
+ const res = await put(url, payload);
107
+ const user = await res.json();
108
+
109
+ return user;
68
110
  },
69
111
 
70
112
  getPaymentIntent: async (uuid, processor, amount, currency, payees) => {
@@ -87,7 +129,7 @@ const addie = {
87
129
  return intent;
88
130
  },
89
131
 
90
- getPaymentIntentWithoutSplits: async (uuid, processor, amount, currency) => {
132
+ getPaymentIntentWithoutSplits: async (uuid, processor, amount, currency, savePaymentMethod = false) => {
91
133
  const timestamp = new Date().getTime() + '';
92
134
  const message = timestamp + uuid + amount + currency;
93
135
  const signature = await sessionless.sign(message);
@@ -96,16 +138,175 @@ const addie = {
96
138
  timestamp,
97
139
  amount,
98
140
  currency,
141
+ savePaymentMethod,
99
142
  "signature": signature
100
143
  };
101
144
 
102
145
  const url = `${addie.baseURL}user/${uuid}/processor/${processor}/intent-without-splits`;
103
- const res = await post(url, payload); // Start here
146
+ const res = await post(url, payload);
104
147
  const intent = await res.json();
105
148
 
106
149
  return intent;
107
150
  },
108
151
 
152
+ // Payment Method Management
153
+ createSetupIntent: async (processor = 'stripe') => {
154
+ const timestamp = new Date().getTime() + '';
155
+ const keys = await sessionless.getKeys();
156
+ const message = timestamp + (keys.pubKey || '');
157
+ const signature = await sessionless.sign(message);
158
+
159
+ const payload = {
160
+ timestamp,
161
+ pubKey: keys.pubKey,
162
+ signature
163
+ };
164
+
165
+ const url = `${addie.baseURL}processor/${processor}/setup-intent`;
166
+ const res = await post(url, payload);
167
+ const setupIntent = await res.json();
168
+
169
+ return setupIntent;
170
+ },
171
+
172
+ getSavedPaymentMethods: async (uuid, processor = 'stripe') => {
173
+ const timestamp = new Date().getTime() + '';
174
+ const message = timestamp + uuid;
175
+ const signature = await sessionless.sign(message);
176
+
177
+ const url = `${addie.baseURL}saved-payment-methods?uuid=${uuid}&timestamp=${timestamp}&processor=${processor}&signature=${signature}`;
178
+ const res = await get(url);
179
+ const result = await res.json();
180
+
181
+ return result;
182
+ },
183
+
184
+ deleteSavedPaymentMethod: async (uuid, paymentMethodId, processor = 'stripe') => {
185
+ const timestamp = new Date().getTime() + '';
186
+ const message = timestamp + uuid;
187
+ const signature = await sessionless.sign(message);
188
+
189
+ const payload = {
190
+ timestamp,
191
+ signature
192
+ };
193
+
194
+ const url = `${addie.baseURL}saved-payment-methods/${paymentMethodId}`;
195
+ const res = await _delete(url, payload);
196
+ const result = await res.json();
197
+
198
+ return result;
199
+ },
200
+
201
+ // Stripe Issuing (Virtual Cards)
202
+ createCardholder: async (individualInfo) => {
203
+ const timestamp = new Date().getTime() + '';
204
+ const keys = await sessionless.getKeys();
205
+ const message = timestamp + keys.pubKey;
206
+ const signature = await sessionless.sign(message);
207
+
208
+ const payload = {
209
+ timestamp,
210
+ pubKey: keys.pubKey,
211
+ signature,
212
+ individualInfo
213
+ };
214
+
215
+ const url = `${addie.baseURL}issuing/cardholder`;
216
+ const res = await post(url, payload);
217
+ const result = await res.json();
218
+
219
+ return result;
220
+ },
221
+
222
+ issueVirtualCard: async (currency = 'usd', spendingLimit) => {
223
+ const timestamp = new Date().getTime() + '';
224
+ const keys = await sessionless.getKeys();
225
+ const message = timestamp + keys.pubKey;
226
+ const signature = await sessionless.sign(message);
227
+
228
+ const payload = {
229
+ timestamp,
230
+ pubKey: keys.pubKey,
231
+ signature,
232
+ currency,
233
+ spendingLimit
234
+ };
235
+
236
+ const url = `${addie.baseURL}issuing/card/virtual`;
237
+ const res = await post(url, payload);
238
+ const result = await res.json();
239
+
240
+ return result;
241
+ },
242
+
243
+ getIssuedCards: async () => {
244
+ const timestamp = new Date().getTime() + '';
245
+ const keys = await sessionless.getKeys();
246
+ const message = timestamp + keys.pubKey;
247
+ const signature = await sessionless.sign(message);
248
+
249
+ const url = `${addie.baseURL}issuing/cards?timestamp=${timestamp}&pubKey=${keys.pubKey}&signature=${signature}`;
250
+ const res = await get(url);
251
+ const result = await res.json();
252
+
253
+ return result;
254
+ },
255
+
256
+ getCardTransactions: async (limit = 10) => {
257
+ const timestamp = new Date().getTime() + '';
258
+ const keys = await sessionless.getKeys();
259
+ const message = timestamp + keys.pubKey;
260
+ const signature = await sessionless.sign(message);
261
+
262
+ const url = `${addie.baseURL}issuing/transactions?timestamp=${timestamp}&pubKey=${keys.pubKey}&signature=${signature}&limit=${limit}`;
263
+ const res = await get(url);
264
+ const result = await res.json();
265
+
266
+ return result;
267
+ },
268
+
269
+ updateCardStatus: async (cardId, status) => {
270
+ const timestamp = new Date().getTime() + '';
271
+ const keys = await sessionless.getKeys();
272
+ const message = timestamp + keys.pubKey + cardId + status;
273
+ const signature = await sessionless.sign(message);
274
+
275
+ const payload = {
276
+ timestamp,
277
+ pubKey: keys.pubKey,
278
+ signature,
279
+ status
280
+ };
281
+
282
+ const url = `${addie.baseURL}issuing/card/${cardId}/status`;
283
+ const res = await patch(url, payload);
284
+ const result = await res.json();
285
+
286
+ return result;
287
+ },
288
+
289
+ // Transfer Processing
290
+ processPaymentTransfers: async (paymentIntentId) => {
291
+ const url = `${addie.baseURL}payment/${paymentIntentId}/process-transfers`;
292
+ const res = await post(url, {});
293
+ const result = await res.json();
294
+
295
+ return result;
296
+ },
297
+
298
+ // Distinct from processPaymentTransfers above: that one moves funds to
299
+ // payout *cards* (Stripe Issuing), this one settles splits to Stripe
300
+ // Connected Accounts. Two different server routes, two different
301
+ // processors on Addie's side — a Connect payout has to use this one.
302
+ processConnectedTransfers: async (paymentIntentId) => {
303
+ const url = `${addie.baseURL}payment/${paymentIntentId}/process-connected-transfers`;
304
+ const res = await post(url, {});
305
+ const result = await res.json();
306
+
307
+ return result;
308
+ },
309
+
109
310
  deleteUser: async (uuid) => {
110
311
  const timestamp = new Date().getTime() + '';
111
312
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "addie-js",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Addie JavaScript client",
5
5
  "main": "addie.js",
6
6
  "scripts": {
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "git+https://github.com/planet-nine-app/addie.git"
11
+ "url": "git+https://github.com/freyja-love-and-magic/addie.git"
12
12
  },
13
13
  "type": "module",
14
14
  "author": "planetnineisaspaceship",