| 50 | TEventCatalog extends WebhookEventCatalog<infer U, any> ? keyof U : never; |
| 51 | |
| 52 | export class Shopify implements TriggerIntegration { |
| 53 | private _options: ShopifyIntegrationOptions; |
| 54 | |
| 55 | private _client?: ReturnType<(typeof this)["createClient"]>; |
| 56 | private _io?: IO; |
| 57 | private _connectionKey?: string; |
| 58 | private _session?: Session; |
| 59 | private _shopDomain: string; |
| 60 | |
| 61 | constructor(private options: ShopifyIntegrationOptions) { |
| 62 | if (Object.keys(options).includes("apiKey") && !options.apiKey) { |
| 63 | throw `Can't create Shopify integration (${options.id}) as apiKey was undefined`; |
| 64 | } |
| 65 | |
| 66 | if (Object.keys(options).includes("apiSecretKey") && !options.apiSecretKey) { |
| 67 | throw `Can't create Shopify integration (${options.id}) as apiSecretKey was undefined`; |
| 68 | } |
| 69 | |
| 70 | if (Object.keys(options).includes("adminAccessToken") && !options.adminAccessToken) { |
| 71 | throw `Can't create Shopify integration (${options.id}) as adminAccessToken was undefined`; |
| 72 | } |
| 73 | |
| 74 | if (Object.keys(options).includes("hostName") && !options.hostName) { |
| 75 | throw `Can't create Shopify integration (${options.id}) as hostName was undefined`; |
| 76 | } |
| 77 | |
| 78 | this._options = options; |
| 79 | // Extract the shop domain if user has entered the full URL |
| 80 | this._shopDomain = this._options.hostName |
| 81 | .replace(/^https?:\/\//, "") // Remove http:// or https:// |
| 82 | .replace(/\/$/, ""); // Remove trailing slash if it exists (e.g. `example.myshopify.com/`) |
| 83 | |
| 84 | // Regular expression to ensure the shopDomain is a valid `.myshopify.com` domain |
| 85 | const shopifyDomainPattern = /^[a-zA-Z0-9-]+\.myshopify\.com$/; |
| 86 | |
| 87 | if (!shopifyDomainPattern.test(this._shopDomain)) { |
| 88 | throw `Can't create Shopify integration (${options.id}) because hostName should be a valid ".myshopify.com" domain, not a custom primary domain. For example: my-domain.myshopify.com`; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | get authSource() { |
| 93 | return this._options.apiKey ? "LOCAL" : "HOSTED"; |
| 94 | } |
| 95 | |
| 96 | get id() { |
| 97 | return this.options.id; |
| 98 | } |
| 99 | |
| 100 | get metadata() { |
| 101 | return { id: "shopify", name: "Shopify" }; |
| 102 | } |
| 103 | |
| 104 | get #source() { |
| 105 | return createWebhookEventSource(this); |
| 106 | } |
| 107 | |
| 108 | get #eventCatalog() { |
| 109 | return createWebhookEventCatalog(this.#source); |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…