stripe-experiment-sync 1.0.3 → 1.0.6
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/{chunk-SNGEJHKN.js → chunk-3UERGK2O.js} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/supabase/index.cjs +70 -44
- package/dist/supabase/index.d.cts +12 -4
- package/dist/supabase/index.d.ts +12 -4
- package/dist/supabase/index.js +65 -44
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -45,7 +45,7 @@ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
|
45
45
|
// package.json
|
|
46
46
|
var package_default = {
|
|
47
47
|
name: "stripe-experiment-sync",
|
|
48
|
-
version: "1.0.
|
|
48
|
+
version: "1.0.6",
|
|
49
49
|
private: false,
|
|
50
50
|
description: "Stripe Sync Engine to sync Stripe data to Postgres",
|
|
51
51
|
type: "module",
|
package/dist/index.js
CHANGED
package/dist/supabase/index.cjs
CHANGED
|
@@ -30,7 +30,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/supabase/index.ts
|
|
31
31
|
var supabase_exports = {};
|
|
32
32
|
__export(supabase_exports, {
|
|
33
|
-
|
|
33
|
+
INSTALLATION_ERROR_SUFFIX: () => INSTALLATION_ERROR_SUFFIX,
|
|
34
|
+
INSTALLATION_INSTALLED_SUFFIX: () => INSTALLATION_INSTALLED_SUFFIX,
|
|
35
|
+
INSTALLATION_STARTED_SUFFIX: () => INSTALLATION_STARTED_SUFFIX,
|
|
36
|
+
STRIPE_SCHEMA_COMMENT_PREFIX: () => STRIPE_SCHEMA_COMMENT_PREFIX,
|
|
37
|
+
SupabaseDeployClient: () => SupabaseSetupClient,
|
|
38
|
+
SupabaseSetupClient: () => SupabaseSetupClient,
|
|
34
39
|
install: () => install,
|
|
35
40
|
setupFunctionCode: () => setupFunctionCode,
|
|
36
41
|
uninstall: () => uninstall,
|
|
@@ -59,7 +64,7 @@ var workerFunctionCode = stripe_worker_default;
|
|
|
59
64
|
// package.json
|
|
60
65
|
var package_default = {
|
|
61
66
|
name: "stripe-experiment-sync",
|
|
62
|
-
version: "1.0.
|
|
67
|
+
version: "1.0.6",
|
|
63
68
|
private: false,
|
|
64
69
|
description: "Stripe Sync Engine to sync Stripe data to Postgres",
|
|
65
70
|
type: "module",
|
|
@@ -128,14 +133,21 @@ var package_default = {
|
|
|
128
133
|
|
|
129
134
|
// src/supabase/supabase.ts
|
|
130
135
|
var import_stripe = __toESM(require("stripe"), 1);
|
|
131
|
-
var
|
|
136
|
+
var STRIPE_SCHEMA_COMMENT_PREFIX = "stripe-sync";
|
|
137
|
+
var INSTALLATION_STARTED_SUFFIX = "installation:started";
|
|
138
|
+
var INSTALLATION_ERROR_SUFFIX = "installation:error";
|
|
139
|
+
var INSTALLATION_INSTALLED_SUFFIX = "installed";
|
|
140
|
+
var SupabaseSetupClient = class {
|
|
132
141
|
api;
|
|
133
142
|
projectRef;
|
|
134
|
-
|
|
143
|
+
projectBaseUrl;
|
|
135
144
|
constructor(options) {
|
|
136
|
-
this.api = new import_supabase_management_js.SupabaseManagementAPI({
|
|
145
|
+
this.api = new import_supabase_management_js.SupabaseManagementAPI({
|
|
146
|
+
accessToken: options.accessToken,
|
|
147
|
+
baseUrl: options.managementApiBaseUrl
|
|
148
|
+
});
|
|
137
149
|
this.projectRef = options.projectRef;
|
|
138
|
-
this.
|
|
150
|
+
this.projectBaseUrl = options.projectBaseUrl || process.env.SUPABASE_BASE_URL || "supabase.co";
|
|
139
151
|
}
|
|
140
152
|
/**
|
|
141
153
|
* Validate that the project exists and we have access
|
|
@@ -222,7 +234,7 @@ var SupabaseDeployClient = class {
|
|
|
222
234
|
'10 seconds',
|
|
223
235
|
$$
|
|
224
236
|
SELECT net.http_post(
|
|
225
|
-
url := 'https://${this.projectRef}.${this.
|
|
237
|
+
url := 'https://${this.projectRef}.${this.projectBaseUrl}/functions/v1/stripe-worker',
|
|
226
238
|
headers := jsonb_build_object(
|
|
227
239
|
'Authorization', 'Bearer ' || (SELECT decrypted_secret FROM vault.decrypted_secrets WHERE name = 'stripe_sync_service_role_key')
|
|
228
240
|
)
|
|
@@ -236,7 +248,7 @@ var SupabaseDeployClient = class {
|
|
|
236
248
|
* Get the webhook URL for this project
|
|
237
249
|
*/
|
|
238
250
|
getWebhookUrl() {
|
|
239
|
-
return `https://${this.projectRef}.${this.
|
|
251
|
+
return `https://${this.projectRef}.${this.projectBaseUrl}/functions/v1/stripe-webhook`;
|
|
240
252
|
}
|
|
241
253
|
/**
|
|
242
254
|
* Get the service role key for this project (needed to invoke Edge Functions)
|
|
@@ -264,13 +276,13 @@ var SupabaseDeployClient = class {
|
|
|
264
276
|
* Get the project URL
|
|
265
277
|
*/
|
|
266
278
|
getProjectUrl() {
|
|
267
|
-
return `https://${this.projectRef}.${this.
|
|
279
|
+
return `https://${this.projectRef}.${this.projectBaseUrl}`;
|
|
268
280
|
}
|
|
269
281
|
/**
|
|
270
282
|
* Invoke an Edge Function
|
|
271
283
|
*/
|
|
272
284
|
async invokeFunction(name, serviceRoleKey) {
|
|
273
|
-
const url = `https://${this.projectRef}.${this.
|
|
285
|
+
const url = `https://${this.projectRef}.${this.projectBaseUrl}/functions/v1/${name}`;
|
|
274
286
|
const response = await fetch(url, {
|
|
275
287
|
method: "POST",
|
|
276
288
|
headers: {
|
|
@@ -327,15 +339,15 @@ var SupabaseDeployClient = class {
|
|
|
327
339
|
WHERE nspname = '${schema}'`
|
|
328
340
|
);
|
|
329
341
|
const comment = commentCheck[0]?.rows?.[0]?.comment;
|
|
330
|
-
if (!comment || !comment.includes(
|
|
342
|
+
if (!comment || !comment.includes(STRIPE_SCHEMA_COMMENT_PREFIX)) {
|
|
331
343
|
throw new Error(
|
|
332
344
|
`Legacy installation detected: Schema '${schema}' and migrations table exist, but missing stripe-sync comment marker. This may be a legacy installation or manually created schema. Please contact support or manually drop the schema before proceeding.`
|
|
333
345
|
);
|
|
334
346
|
}
|
|
335
|
-
if (comment.includes(
|
|
347
|
+
if (comment.includes(INSTALLATION_STARTED_SUFFIX)) {
|
|
336
348
|
return false;
|
|
337
349
|
}
|
|
338
|
-
if (comment.includes(
|
|
350
|
+
if (comment.includes(INSTALLATION_ERROR_SUFFIX)) {
|
|
339
351
|
throw new Error(
|
|
340
352
|
`Installation failed: Schema '${schema}' exists but installation encountered an error. Comment: ${comment}. Please uninstall and install again.`
|
|
341
353
|
);
|
|
@@ -424,41 +436,50 @@ var SupabaseDeployClient = class {
|
|
|
424
436
|
throw new Error(`Uninstall failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
425
437
|
}
|
|
426
438
|
}
|
|
439
|
+
async install(stripeKey) {
|
|
440
|
+
const trimmedStripeKey = stripeKey.trim();
|
|
441
|
+
if (!trimmedStripeKey.startsWith("sk_") && !trimmedStripeKey.startsWith("rk_")) {
|
|
442
|
+
throw new Error('Stripe key should start with "sk_" or "rk_"');
|
|
443
|
+
}
|
|
444
|
+
try {
|
|
445
|
+
await this.validateProject();
|
|
446
|
+
await this.runSQL(`CREATE SCHEMA IF NOT EXISTS stripe`);
|
|
447
|
+
await this.updateInstallationComment(
|
|
448
|
+
`${STRIPE_SCHEMA_COMMENT_PREFIX} v${package_default.version} ${INSTALLATION_STARTED_SUFFIX}`
|
|
449
|
+
);
|
|
450
|
+
await this.deployFunction("stripe-setup", setupFunctionCode);
|
|
451
|
+
await this.deployFunction("stripe-webhook", webhookFunctionCode);
|
|
452
|
+
await this.deployFunction("stripe-worker", workerFunctionCode);
|
|
453
|
+
await this.setSecrets([{ name: "STRIPE_SECRET_KEY", value: trimmedStripeKey }]);
|
|
454
|
+
const serviceRoleKey = await this.getServiceRoleKey();
|
|
455
|
+
const setupResult = await this.invokeFunction("stripe-setup", serviceRoleKey);
|
|
456
|
+
if (!setupResult.success) {
|
|
457
|
+
throw new Error(`Setup failed: ${setupResult.error}`);
|
|
458
|
+
}
|
|
459
|
+
try {
|
|
460
|
+
await this.setupPgCronJob();
|
|
461
|
+
} catch {
|
|
462
|
+
}
|
|
463
|
+
await this.updateInstallationComment(
|
|
464
|
+
`${STRIPE_SCHEMA_COMMENT_PREFIX} v${package_default.version} ${INSTALLATION_INSTALLED_SUFFIX}`
|
|
465
|
+
);
|
|
466
|
+
} catch (error) {
|
|
467
|
+
await this.updateInstallationComment(
|
|
468
|
+
`${STRIPE_SCHEMA_COMMENT_PREFIX} v${package_default.version} ${INSTALLATION_ERROR_SUFFIX} - ${error instanceof Error ? error.message : String(error)}`
|
|
469
|
+
);
|
|
470
|
+
throw error;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
427
473
|
};
|
|
428
474
|
async function install(params) {
|
|
429
475
|
const { supabaseAccessToken, supabaseProjectRef, stripeKey } = params;
|
|
430
|
-
const
|
|
431
|
-
if (!trimmedStripeKey.startsWith("sk_") && !trimmedStripeKey.startsWith("rk_")) {
|
|
432
|
-
throw new Error('Stripe key should start with "sk_" or "rk_"');
|
|
433
|
-
}
|
|
434
|
-
const client = new SupabaseDeployClient({
|
|
476
|
+
const client = new SupabaseSetupClient({
|
|
435
477
|
accessToken: supabaseAccessToken,
|
|
436
|
-
projectRef: supabaseProjectRef
|
|
478
|
+
projectRef: supabaseProjectRef,
|
|
479
|
+
projectBaseUrl: params.baseProjectUrl,
|
|
480
|
+
managementApiBaseUrl: params.baseManagementApiUrl
|
|
437
481
|
});
|
|
438
|
-
|
|
439
|
-
await client.validateProject();
|
|
440
|
-
await client.runSQL(`CREATE SCHEMA IF NOT EXISTS stripe`);
|
|
441
|
-
await client.updateInstallationComment(`stripe-sync v${package_default.version} installation:started`);
|
|
442
|
-
await client.deployFunction("stripe-setup", setupFunctionCode);
|
|
443
|
-
await client.deployFunction("stripe-webhook", webhookFunctionCode);
|
|
444
|
-
await client.deployFunction("stripe-worker", workerFunctionCode);
|
|
445
|
-
await client.setSecrets([{ name: "STRIPE_SECRET_KEY", value: trimmedStripeKey }]);
|
|
446
|
-
const serviceRoleKey = await client.getServiceRoleKey();
|
|
447
|
-
const setupResult = await client.invokeFunction("stripe-setup", serviceRoleKey);
|
|
448
|
-
if (!setupResult.success) {
|
|
449
|
-
throw new Error(`Setup failed: ${setupResult.error}`);
|
|
450
|
-
}
|
|
451
|
-
try {
|
|
452
|
-
await client.setupPgCronJob();
|
|
453
|
-
} catch {
|
|
454
|
-
}
|
|
455
|
-
await client.updateInstallationComment(`stripe-sync v${package_default.version} installed`);
|
|
456
|
-
} catch (error) {
|
|
457
|
-
await client.updateInstallationComment(
|
|
458
|
-
`stripe-sync v${package_default.version} installation:error - ${error instanceof Error ? error.message : String(error)}`
|
|
459
|
-
);
|
|
460
|
-
throw error;
|
|
461
|
-
}
|
|
482
|
+
await client.install(stripeKey);
|
|
462
483
|
}
|
|
463
484
|
async function uninstall(params) {
|
|
464
485
|
const { supabaseAccessToken, supabaseProjectRef, stripeKey } = params;
|
|
@@ -466,7 +487,7 @@ async function uninstall(params) {
|
|
|
466
487
|
if (!trimmedStripeKey.startsWith("sk_") && !trimmedStripeKey.startsWith("rk_")) {
|
|
467
488
|
throw new Error('Stripe key should start with "sk_" or "rk_"');
|
|
468
489
|
}
|
|
469
|
-
const client = new
|
|
490
|
+
const client = new SupabaseSetupClient({
|
|
470
491
|
accessToken: supabaseAccessToken,
|
|
471
492
|
projectRef: supabaseProjectRef
|
|
472
493
|
});
|
|
@@ -474,7 +495,12 @@ async function uninstall(params) {
|
|
|
474
495
|
}
|
|
475
496
|
// Annotate the CommonJS export names for ESM import in node:
|
|
476
497
|
0 && (module.exports = {
|
|
498
|
+
INSTALLATION_ERROR_SUFFIX,
|
|
499
|
+
INSTALLATION_INSTALLED_SUFFIX,
|
|
500
|
+
INSTALLATION_STARTED_SUFFIX,
|
|
501
|
+
STRIPE_SCHEMA_COMMENT_PREFIX,
|
|
477
502
|
SupabaseDeployClient,
|
|
503
|
+
SupabaseSetupClient,
|
|
478
504
|
install,
|
|
479
505
|
setupFunctionCode,
|
|
480
506
|
uninstall,
|
|
@@ -1,17 +1,22 @@
|
|
|
1
|
+
declare const STRIPE_SCHEMA_COMMENT_PREFIX = "stripe-sync";
|
|
2
|
+
declare const INSTALLATION_STARTED_SUFFIX = "installation:started";
|
|
3
|
+
declare const INSTALLATION_ERROR_SUFFIX = "installation:error";
|
|
4
|
+
declare const INSTALLATION_INSTALLED_SUFFIX = "installed";
|
|
1
5
|
interface DeployClientOptions {
|
|
2
6
|
accessToken: string;
|
|
3
7
|
projectRef: string;
|
|
4
|
-
|
|
8
|
+
projectBaseUrl?: string;
|
|
9
|
+
managementApiBaseUrl?: string;
|
|
5
10
|
}
|
|
6
11
|
interface ProjectInfo {
|
|
7
12
|
id: string;
|
|
8
13
|
name: string;
|
|
9
14
|
region: string;
|
|
10
15
|
}
|
|
11
|
-
declare class
|
|
16
|
+
declare class SupabaseSetupClient {
|
|
12
17
|
private api;
|
|
13
18
|
private projectRef;
|
|
14
|
-
private
|
|
19
|
+
private projectBaseUrl;
|
|
15
20
|
constructor(options: DeployClientOptions);
|
|
16
21
|
/**
|
|
17
22
|
* Validate that the project exists and we have access
|
|
@@ -88,11 +93,14 @@ declare class SupabaseDeployClient {
|
|
|
88
93
|
* Removes all Edge Functions, secrets, database resources, and Stripe webhooks
|
|
89
94
|
*/
|
|
90
95
|
uninstall(stripeSecretKey: string): Promise<void>;
|
|
96
|
+
install(stripeKey: string): Promise<void>;
|
|
91
97
|
}
|
|
92
98
|
declare function install(params: {
|
|
93
99
|
supabaseAccessToken: string;
|
|
94
100
|
supabaseProjectRef: string;
|
|
95
101
|
stripeKey: string;
|
|
102
|
+
baseProjectUrl?: string;
|
|
103
|
+
baseManagementApiUrl?: string;
|
|
96
104
|
}): Promise<void>;
|
|
97
105
|
declare function uninstall(params: {
|
|
98
106
|
supabaseAccessToken: string;
|
|
@@ -104,4 +112,4 @@ declare const setupFunctionCode: string;
|
|
|
104
112
|
declare const webhookFunctionCode: string;
|
|
105
113
|
declare const workerFunctionCode: string;
|
|
106
114
|
|
|
107
|
-
export { type DeployClientOptions, type ProjectInfo, SupabaseDeployClient, install, setupFunctionCode, uninstall, webhookFunctionCode, workerFunctionCode };
|
|
115
|
+
export { type DeployClientOptions, INSTALLATION_ERROR_SUFFIX, INSTALLATION_INSTALLED_SUFFIX, INSTALLATION_STARTED_SUFFIX, type ProjectInfo, STRIPE_SCHEMA_COMMENT_PREFIX, SupabaseSetupClient as SupabaseDeployClient, SupabaseSetupClient, install, setupFunctionCode, uninstall, webhookFunctionCode, workerFunctionCode };
|
package/dist/supabase/index.d.ts
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
|
+
declare const STRIPE_SCHEMA_COMMENT_PREFIX = "stripe-sync";
|
|
2
|
+
declare const INSTALLATION_STARTED_SUFFIX = "installation:started";
|
|
3
|
+
declare const INSTALLATION_ERROR_SUFFIX = "installation:error";
|
|
4
|
+
declare const INSTALLATION_INSTALLED_SUFFIX = "installed";
|
|
1
5
|
interface DeployClientOptions {
|
|
2
6
|
accessToken: string;
|
|
3
7
|
projectRef: string;
|
|
4
|
-
|
|
8
|
+
projectBaseUrl?: string;
|
|
9
|
+
managementApiBaseUrl?: string;
|
|
5
10
|
}
|
|
6
11
|
interface ProjectInfo {
|
|
7
12
|
id: string;
|
|
8
13
|
name: string;
|
|
9
14
|
region: string;
|
|
10
15
|
}
|
|
11
|
-
declare class
|
|
16
|
+
declare class SupabaseSetupClient {
|
|
12
17
|
private api;
|
|
13
18
|
private projectRef;
|
|
14
|
-
private
|
|
19
|
+
private projectBaseUrl;
|
|
15
20
|
constructor(options: DeployClientOptions);
|
|
16
21
|
/**
|
|
17
22
|
* Validate that the project exists and we have access
|
|
@@ -88,11 +93,14 @@ declare class SupabaseDeployClient {
|
|
|
88
93
|
* Removes all Edge Functions, secrets, database resources, and Stripe webhooks
|
|
89
94
|
*/
|
|
90
95
|
uninstall(stripeSecretKey: string): Promise<void>;
|
|
96
|
+
install(stripeKey: string): Promise<void>;
|
|
91
97
|
}
|
|
92
98
|
declare function install(params: {
|
|
93
99
|
supabaseAccessToken: string;
|
|
94
100
|
supabaseProjectRef: string;
|
|
95
101
|
stripeKey: string;
|
|
102
|
+
baseProjectUrl?: string;
|
|
103
|
+
baseManagementApiUrl?: string;
|
|
96
104
|
}): Promise<void>;
|
|
97
105
|
declare function uninstall(params: {
|
|
98
106
|
supabaseAccessToken: string;
|
|
@@ -104,4 +112,4 @@ declare const setupFunctionCode: string;
|
|
|
104
112
|
declare const webhookFunctionCode: string;
|
|
105
113
|
declare const workerFunctionCode: string;
|
|
106
114
|
|
|
107
|
-
export { type DeployClientOptions, type ProjectInfo, SupabaseDeployClient, install, setupFunctionCode, uninstall, webhookFunctionCode, workerFunctionCode };
|
|
115
|
+
export { type DeployClientOptions, INSTALLATION_ERROR_SUFFIX, INSTALLATION_INSTALLED_SUFFIX, INSTALLATION_STARTED_SUFFIX, type ProjectInfo, STRIPE_SCHEMA_COMMENT_PREFIX, SupabaseSetupClient as SupabaseDeployClient, SupabaseSetupClient, install, setupFunctionCode, uninstall, webhookFunctionCode, workerFunctionCode };
|
package/dist/supabase/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
package_default
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-3UERGK2O.js";
|
|
4
4
|
|
|
5
5
|
// src/supabase/supabase.ts
|
|
6
6
|
import { SupabaseManagementAPI } from "supabase-management-js";
|
|
@@ -21,14 +21,21 @@ var workerFunctionCode = stripe_worker_default;
|
|
|
21
21
|
|
|
22
22
|
// src/supabase/supabase.ts
|
|
23
23
|
import Stripe from "stripe";
|
|
24
|
-
var
|
|
24
|
+
var STRIPE_SCHEMA_COMMENT_PREFIX = "stripe-sync";
|
|
25
|
+
var INSTALLATION_STARTED_SUFFIX = "installation:started";
|
|
26
|
+
var INSTALLATION_ERROR_SUFFIX = "installation:error";
|
|
27
|
+
var INSTALLATION_INSTALLED_SUFFIX = "installed";
|
|
28
|
+
var SupabaseSetupClient = class {
|
|
25
29
|
api;
|
|
26
30
|
projectRef;
|
|
27
|
-
|
|
31
|
+
projectBaseUrl;
|
|
28
32
|
constructor(options) {
|
|
29
|
-
this.api = new SupabaseManagementAPI({
|
|
33
|
+
this.api = new SupabaseManagementAPI({
|
|
34
|
+
accessToken: options.accessToken,
|
|
35
|
+
baseUrl: options.managementApiBaseUrl
|
|
36
|
+
});
|
|
30
37
|
this.projectRef = options.projectRef;
|
|
31
|
-
this.
|
|
38
|
+
this.projectBaseUrl = options.projectBaseUrl || process.env.SUPABASE_BASE_URL || "supabase.co";
|
|
32
39
|
}
|
|
33
40
|
/**
|
|
34
41
|
* Validate that the project exists and we have access
|
|
@@ -115,7 +122,7 @@ var SupabaseDeployClient = class {
|
|
|
115
122
|
'10 seconds',
|
|
116
123
|
$$
|
|
117
124
|
SELECT net.http_post(
|
|
118
|
-
url := 'https://${this.projectRef}.${this.
|
|
125
|
+
url := 'https://${this.projectRef}.${this.projectBaseUrl}/functions/v1/stripe-worker',
|
|
119
126
|
headers := jsonb_build_object(
|
|
120
127
|
'Authorization', 'Bearer ' || (SELECT decrypted_secret FROM vault.decrypted_secrets WHERE name = 'stripe_sync_service_role_key')
|
|
121
128
|
)
|
|
@@ -129,7 +136,7 @@ var SupabaseDeployClient = class {
|
|
|
129
136
|
* Get the webhook URL for this project
|
|
130
137
|
*/
|
|
131
138
|
getWebhookUrl() {
|
|
132
|
-
return `https://${this.projectRef}.${this.
|
|
139
|
+
return `https://${this.projectRef}.${this.projectBaseUrl}/functions/v1/stripe-webhook`;
|
|
133
140
|
}
|
|
134
141
|
/**
|
|
135
142
|
* Get the service role key for this project (needed to invoke Edge Functions)
|
|
@@ -157,13 +164,13 @@ var SupabaseDeployClient = class {
|
|
|
157
164
|
* Get the project URL
|
|
158
165
|
*/
|
|
159
166
|
getProjectUrl() {
|
|
160
|
-
return `https://${this.projectRef}.${this.
|
|
167
|
+
return `https://${this.projectRef}.${this.projectBaseUrl}`;
|
|
161
168
|
}
|
|
162
169
|
/**
|
|
163
170
|
* Invoke an Edge Function
|
|
164
171
|
*/
|
|
165
172
|
async invokeFunction(name, serviceRoleKey) {
|
|
166
|
-
const url = `https://${this.projectRef}.${this.
|
|
173
|
+
const url = `https://${this.projectRef}.${this.projectBaseUrl}/functions/v1/${name}`;
|
|
167
174
|
const response = await fetch(url, {
|
|
168
175
|
method: "POST",
|
|
169
176
|
headers: {
|
|
@@ -220,15 +227,15 @@ var SupabaseDeployClient = class {
|
|
|
220
227
|
WHERE nspname = '${schema}'`
|
|
221
228
|
);
|
|
222
229
|
const comment = commentCheck[0]?.rows?.[0]?.comment;
|
|
223
|
-
if (!comment || !comment.includes(
|
|
230
|
+
if (!comment || !comment.includes(STRIPE_SCHEMA_COMMENT_PREFIX)) {
|
|
224
231
|
throw new Error(
|
|
225
232
|
`Legacy installation detected: Schema '${schema}' and migrations table exist, but missing stripe-sync comment marker. This may be a legacy installation or manually created schema. Please contact support or manually drop the schema before proceeding.`
|
|
226
233
|
);
|
|
227
234
|
}
|
|
228
|
-
if (comment.includes(
|
|
235
|
+
if (comment.includes(INSTALLATION_STARTED_SUFFIX)) {
|
|
229
236
|
return false;
|
|
230
237
|
}
|
|
231
|
-
if (comment.includes(
|
|
238
|
+
if (comment.includes(INSTALLATION_ERROR_SUFFIX)) {
|
|
232
239
|
throw new Error(
|
|
233
240
|
`Installation failed: Schema '${schema}' exists but installation encountered an error. Comment: ${comment}. Please uninstall and install again.`
|
|
234
241
|
);
|
|
@@ -317,41 +324,50 @@ var SupabaseDeployClient = class {
|
|
|
317
324
|
throw new Error(`Uninstall failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
318
325
|
}
|
|
319
326
|
}
|
|
327
|
+
async install(stripeKey) {
|
|
328
|
+
const trimmedStripeKey = stripeKey.trim();
|
|
329
|
+
if (!trimmedStripeKey.startsWith("sk_") && !trimmedStripeKey.startsWith("rk_")) {
|
|
330
|
+
throw new Error('Stripe key should start with "sk_" or "rk_"');
|
|
331
|
+
}
|
|
332
|
+
try {
|
|
333
|
+
await this.validateProject();
|
|
334
|
+
await this.runSQL(`CREATE SCHEMA IF NOT EXISTS stripe`);
|
|
335
|
+
await this.updateInstallationComment(
|
|
336
|
+
`${STRIPE_SCHEMA_COMMENT_PREFIX} v${package_default.version} ${INSTALLATION_STARTED_SUFFIX}`
|
|
337
|
+
);
|
|
338
|
+
await this.deployFunction("stripe-setup", setupFunctionCode);
|
|
339
|
+
await this.deployFunction("stripe-webhook", webhookFunctionCode);
|
|
340
|
+
await this.deployFunction("stripe-worker", workerFunctionCode);
|
|
341
|
+
await this.setSecrets([{ name: "STRIPE_SECRET_KEY", value: trimmedStripeKey }]);
|
|
342
|
+
const serviceRoleKey = await this.getServiceRoleKey();
|
|
343
|
+
const setupResult = await this.invokeFunction("stripe-setup", serviceRoleKey);
|
|
344
|
+
if (!setupResult.success) {
|
|
345
|
+
throw new Error(`Setup failed: ${setupResult.error}`);
|
|
346
|
+
}
|
|
347
|
+
try {
|
|
348
|
+
await this.setupPgCronJob();
|
|
349
|
+
} catch {
|
|
350
|
+
}
|
|
351
|
+
await this.updateInstallationComment(
|
|
352
|
+
`${STRIPE_SCHEMA_COMMENT_PREFIX} v${package_default.version} ${INSTALLATION_INSTALLED_SUFFIX}`
|
|
353
|
+
);
|
|
354
|
+
} catch (error) {
|
|
355
|
+
await this.updateInstallationComment(
|
|
356
|
+
`${STRIPE_SCHEMA_COMMENT_PREFIX} v${package_default.version} ${INSTALLATION_ERROR_SUFFIX} - ${error instanceof Error ? error.message : String(error)}`
|
|
357
|
+
);
|
|
358
|
+
throw error;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
320
361
|
};
|
|
321
362
|
async function install(params) {
|
|
322
363
|
const { supabaseAccessToken, supabaseProjectRef, stripeKey } = params;
|
|
323
|
-
const
|
|
324
|
-
if (!trimmedStripeKey.startsWith("sk_") && !trimmedStripeKey.startsWith("rk_")) {
|
|
325
|
-
throw new Error('Stripe key should start with "sk_" or "rk_"');
|
|
326
|
-
}
|
|
327
|
-
const client = new SupabaseDeployClient({
|
|
364
|
+
const client = new SupabaseSetupClient({
|
|
328
365
|
accessToken: supabaseAccessToken,
|
|
329
|
-
projectRef: supabaseProjectRef
|
|
366
|
+
projectRef: supabaseProjectRef,
|
|
367
|
+
projectBaseUrl: params.baseProjectUrl,
|
|
368
|
+
managementApiBaseUrl: params.baseManagementApiUrl
|
|
330
369
|
});
|
|
331
|
-
|
|
332
|
-
await client.validateProject();
|
|
333
|
-
await client.runSQL(`CREATE SCHEMA IF NOT EXISTS stripe`);
|
|
334
|
-
await client.updateInstallationComment(`stripe-sync v${package_default.version} installation:started`);
|
|
335
|
-
await client.deployFunction("stripe-setup", setupFunctionCode);
|
|
336
|
-
await client.deployFunction("stripe-webhook", webhookFunctionCode);
|
|
337
|
-
await client.deployFunction("stripe-worker", workerFunctionCode);
|
|
338
|
-
await client.setSecrets([{ name: "STRIPE_SECRET_KEY", value: trimmedStripeKey }]);
|
|
339
|
-
const serviceRoleKey = await client.getServiceRoleKey();
|
|
340
|
-
const setupResult = await client.invokeFunction("stripe-setup", serviceRoleKey);
|
|
341
|
-
if (!setupResult.success) {
|
|
342
|
-
throw new Error(`Setup failed: ${setupResult.error}`);
|
|
343
|
-
}
|
|
344
|
-
try {
|
|
345
|
-
await client.setupPgCronJob();
|
|
346
|
-
} catch {
|
|
347
|
-
}
|
|
348
|
-
await client.updateInstallationComment(`stripe-sync v${package_default.version} installed`);
|
|
349
|
-
} catch (error) {
|
|
350
|
-
await client.updateInstallationComment(
|
|
351
|
-
`stripe-sync v${package_default.version} installation:error - ${error instanceof Error ? error.message : String(error)}`
|
|
352
|
-
);
|
|
353
|
-
throw error;
|
|
354
|
-
}
|
|
370
|
+
await client.install(stripeKey);
|
|
355
371
|
}
|
|
356
372
|
async function uninstall(params) {
|
|
357
373
|
const { supabaseAccessToken, supabaseProjectRef, stripeKey } = params;
|
|
@@ -359,14 +375,19 @@ async function uninstall(params) {
|
|
|
359
375
|
if (!trimmedStripeKey.startsWith("sk_") && !trimmedStripeKey.startsWith("rk_")) {
|
|
360
376
|
throw new Error('Stripe key should start with "sk_" or "rk_"');
|
|
361
377
|
}
|
|
362
|
-
const client = new
|
|
378
|
+
const client = new SupabaseSetupClient({
|
|
363
379
|
accessToken: supabaseAccessToken,
|
|
364
380
|
projectRef: supabaseProjectRef
|
|
365
381
|
});
|
|
366
382
|
await client.uninstall(trimmedStripeKey);
|
|
367
383
|
}
|
|
368
384
|
export {
|
|
369
|
-
|
|
385
|
+
INSTALLATION_ERROR_SUFFIX,
|
|
386
|
+
INSTALLATION_INSTALLED_SUFFIX,
|
|
387
|
+
INSTALLATION_STARTED_SUFFIX,
|
|
388
|
+
STRIPE_SCHEMA_COMMENT_PREFIX,
|
|
389
|
+
SupabaseSetupClient as SupabaseDeployClient,
|
|
390
|
+
SupabaseSetupClient,
|
|
370
391
|
install,
|
|
371
392
|
setupFunctionCode,
|
|
372
393
|
uninstall,
|