@adport/provider-gtm 0.0.0-stage → 0.9.0
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/LICENSE +201 -0
- package/README.md +45 -2
- package/dist/index.d.ts +44 -0
- package/dist/index.js +220 -0
- package/dist/index.js.map +1 -0
- package/package.json +45 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Yannick Westermann
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,46 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Google Tag Manager provider
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Google Tag Manager API v2 configuration access for Adport. OAuth credentials are
|
|
4
|
+
stored separately from Google Ads. Enable `tagmanager.googleapis.com` on your
|
|
5
|
+
Google Cloud project, create a Desktop OAuth client, set `GTM_CLIENT_SECRET` in
|
|
6
|
+
your terminal, then run `adport connect gtm`. Alternatively set `GTM_CLIENT_ID`,
|
|
7
|
+
`GTM_CLIENT_SECRET` and `GTM_REFRESH_TOKEN` for local CLI/stdio use.
|
|
8
|
+
|
|
9
|
+
Read accounts, containers, installation snippets, workspaces, tags, triggers, variables, saved versions,
|
|
10
|
+
the live version, and pending workspace changes. Lists expose native
|
|
11
|
+
`nextPageToken`; pass it as `page_token` to continue. GTM supplies configuration,
|
|
12
|
+
not website traffic, runtime variable values or conversion reports.
|
|
13
|
+
|
|
14
|
+
Create workspaces and create/update tags, triggers and variables using native
|
|
15
|
+
camelCase API configuration fields. Every mutation uses the shared two-step
|
|
16
|
+
policy engine. Previews only read upstream configuration; `serverValidated` is
|
|
17
|
+
false because GTM has no validate-only mutation option. Draft changes do not
|
|
18
|
+
publish. Updates require the resource's latest `expected_fingerprint`.
|
|
19
|
+
|
|
20
|
+
To release configuration:
|
|
21
|
+
|
|
22
|
+
1. Inspect the complete draft and call `gtm_workspace_status`.
|
|
23
|
+
2. Preview/apply `gtm_create_version` with the returned `expected_workspace_hash`.
|
|
24
|
+
This includes **all** workspace changes and Google replaces the workspace.
|
|
25
|
+
3. Inspect the resulting version and test it using GTM Preview/Tag Assistant.
|
|
26
|
+
4. Preview/apply `gtm_publish_version` with the saved version fingerprint and
|
|
27
|
+
`expected_live_version_id` (`0` for a never-published container).
|
|
28
|
+
|
|
29
|
+
Version publishing is a separate explicit approval. Changes to reviewed resources,
|
|
30
|
+
workspace changes or the live version require a fresh read/preview. The API cannot
|
|
31
|
+
install GTM on a website or supply missing data-layer events. Google Ads conversion
|
|
32
|
+
actions are created separately with the Google Ads tools. This initial connector
|
|
33
|
+
does not delete containers/resources or manage account users.
|
|
34
|
+
|
|
35
|
+
Cloud uses the existing Google application with a separate `/api/oauth/gtm/callback`
|
|
36
|
+
and these scopes: `tagmanager.edit.containers`, `tagmanager.edit.containerversions`,
|
|
37
|
+
`tagmanager.publish`. These cover configuration reads too; no redundant readonly,
|
|
38
|
+
container deletion or user-management scopes are requested. `GTM_OAUTH_ENABLED`
|
|
39
|
+
defaults false until the application's GTM configuration is ready for external users.
|
|
40
|
+
`GTM_TEST_ORGANIZATION_IDS` permits explicitly named internal review projects only.
|
|
41
|
+
Users select which GTM accounts their project can access in Analytics & tracking.
|
|
42
|
+
GTM accounts do not use advertising account slots. Containers within an enabled account share
|
|
43
|
+
that account's access boundary.
|
|
44
|
+
|
|
45
|
+
Disconnecting GTM deletes Adport's stored grant. Google app-wide revocation is
|
|
46
|
+
manual because it can also revoke Google Ads access granted to the same app.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { AdProvider, Account, NormalizedQuery, Report, WriteOperation, WritePreview, WriteResult, CredentialStore, ProviderModule } from '@adport/core';
|
|
2
|
+
export { GTM_SCOPES, gtmTools } from '@adport/core';
|
|
3
|
+
|
|
4
|
+
interface GtmCredentials {
|
|
5
|
+
clientId: string;
|
|
6
|
+
clientSecret: string;
|
|
7
|
+
refreshToken: string;
|
|
8
|
+
}
|
|
9
|
+
type GtmResource = Record<string, unknown>;
|
|
10
|
+
declare const GTM_API_BASE = "https://tagmanager.googleapis.com/tagmanager/v2";
|
|
11
|
+
/** Fixed-origin REST client. Paths are constructed from validated numeric IDs, never caller URLs. */
|
|
12
|
+
declare class GtmClient {
|
|
13
|
+
private readonly credentials;
|
|
14
|
+
private readonly fetchImpl;
|
|
15
|
+
private accessToken?;
|
|
16
|
+
constructor(credentials: GtmCredentials, fetchImpl?: typeof fetch);
|
|
17
|
+
request(path: string, method?: string, body?: unknown, query?: Record<string, string>): Promise<GtmResource>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare class GtmProvider implements AdProvider {
|
|
21
|
+
private readonly client;
|
|
22
|
+
readonly id = "gtm";
|
|
23
|
+
constructor(client: GtmClient);
|
|
24
|
+
capabilities(): {
|
|
25
|
+
serverDryRun: boolean;
|
|
26
|
+
reporting: boolean;
|
|
27
|
+
};
|
|
28
|
+
listAccounts(): Promise<Account[]>;
|
|
29
|
+
report(_query: NormalizedQuery): Promise<Report>;
|
|
30
|
+
read(accountId: string, suffix: string, query?: Record<string, string>): Promise<GtmResource>;
|
|
31
|
+
workspaceStatus(accountId: string, containerId: string, workspaceId: string): Promise<{
|
|
32
|
+
workspace: GtmResource;
|
|
33
|
+
status: GtmResource;
|
|
34
|
+
workspace_hash: string;
|
|
35
|
+
}>;
|
|
36
|
+
private plan;
|
|
37
|
+
previewWrite(op: WriteOperation): Promise<WritePreview>;
|
|
38
|
+
applyWrite(op: WriteOperation): Promise<WriteResult>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
declare function resolveGtmCredentials(store: CredentialStore): Promise<GtmCredentials | undefined>;
|
|
42
|
+
declare function createGtmModule(store: CredentialStore): Promise<ProviderModule | undefined>;
|
|
43
|
+
|
|
44
|
+
export { GTM_API_BASE, GtmClient, type GtmCredentials, GtmProvider, createGtmModule, resolveGtmCredentials };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { gtmTools } from "@adport/core";
|
|
3
|
+
|
|
4
|
+
// src/client.ts
|
|
5
|
+
import { AdportError } from "@adport/core";
|
|
6
|
+
var GTM_API_BASE = "https://tagmanager.googleapis.com/tagmanager/v2";
|
|
7
|
+
var resourcePaths = [
|
|
8
|
+
/^accounts$/,
|
|
9
|
+
/^accounts\/\d+\/containers$/,
|
|
10
|
+
/^accounts\/\d+\/containers\/\d+(?::snippet)?$/,
|
|
11
|
+
/^accounts\/\d+\/containers\/\d+\/workspaces$/,
|
|
12
|
+
/^accounts\/\d+\/containers\/\d+\/workspaces\/\d+(?:\/status|:create_version)?$/,
|
|
13
|
+
/^accounts\/\d+\/containers\/\d+\/workspaces\/\d+\/(?:tags|triggers|variables)(?:\/\d+)?$/,
|
|
14
|
+
/^accounts\/\d+\/containers\/\d+\/version_headers$/,
|
|
15
|
+
/^accounts\/\d+\/containers\/\d+\/versions:live$/,
|
|
16
|
+
/^accounts\/\d+\/containers\/\d+\/versions\/\d+(?::publish)?$/
|
|
17
|
+
];
|
|
18
|
+
var GtmClient = class {
|
|
19
|
+
constructor(credentials, fetchImpl = fetch) {
|
|
20
|
+
this.credentials = credentials;
|
|
21
|
+
this.fetchImpl = fetchImpl;
|
|
22
|
+
}
|
|
23
|
+
credentials;
|
|
24
|
+
fetchImpl;
|
|
25
|
+
accessToken;
|
|
26
|
+
async request(path, method = "GET", body, query = {}) {
|
|
27
|
+
if (!resourcePaths.some((pattern) => pattern.test(path))) {
|
|
28
|
+
throw new AdportError("INVALID_INPUT", "Invalid Google Tag Manager resource path.");
|
|
29
|
+
}
|
|
30
|
+
if (!this.accessToken || this.accessToken.expiresAt <= Date.now()) {
|
|
31
|
+
const response2 = await this.fetchImpl("https://oauth2.googleapis.com/token", {
|
|
32
|
+
method: "POST",
|
|
33
|
+
redirect: "error",
|
|
34
|
+
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
35
|
+
body: new URLSearchParams({
|
|
36
|
+
client_id: this.credentials.clientId,
|
|
37
|
+
client_secret: this.credentials.clientSecret,
|
|
38
|
+
refresh_token: this.credentials.refreshToken,
|
|
39
|
+
grant_type: "refresh_token"
|
|
40
|
+
})
|
|
41
|
+
});
|
|
42
|
+
const token = await response2.json().catch(() => ({}));
|
|
43
|
+
if (!response2.ok || !token.access_token) throw new AdportError("PROVIDER_ERROR", "Google Tag Manager authorization expired or was revoked. Reconnect GTM.");
|
|
44
|
+
this.accessToken = { token: token.access_token, expiresAt: Date.now() + (Number(token.expires_in ?? 3600) - 60) * 1e3 };
|
|
45
|
+
}
|
|
46
|
+
const params = new URLSearchParams(query);
|
|
47
|
+
const response = await this.fetchImpl(`${GTM_API_BASE}/${path}${params.size ? `?${params}` : ""}`, {
|
|
48
|
+
method,
|
|
49
|
+
redirect: "error",
|
|
50
|
+
headers: { authorization: `Bearer ${this.accessToken.token}`, "content-type": "application/json" },
|
|
51
|
+
...body === void 0 ? {} : { body: JSON.stringify(body) }
|
|
52
|
+
});
|
|
53
|
+
const result = await response.json().catch(() => ({}));
|
|
54
|
+
if (!response.ok) throw new AdportError("PROVIDER_ERROR", `Google Tag Manager API request failed (HTTP ${response.status}). Check GTM permissions, API enablement and the requested resource.`, { status: response.status });
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// src/provider.ts
|
|
60
|
+
import { createHash } from "crypto";
|
|
61
|
+
import {
|
|
62
|
+
AdportError as AdportError2,
|
|
63
|
+
gtmWriteSchemas
|
|
64
|
+
} from "@adport/core";
|
|
65
|
+
function numeric(value) {
|
|
66
|
+
if (typeof value !== "string" || !/^\d+$/.test(value)) throw new AdportError2("INVALID_INPUT", "GTM IDs must be numeric strings.");
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
function stable(value) {
|
|
70
|
+
if (Array.isArray(value)) return value.map(stable);
|
|
71
|
+
if (value && typeof value === "object") return Object.fromEntries(Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([key, item]) => [key, stable(item)]));
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
function assertFingerprint(resource, expected) {
|
|
75
|
+
if (!expected || resource.fingerprint !== expected) throw new AdportError2("PENDING_MISMATCH", "GTM configuration changed. Read the resource and preview again.");
|
|
76
|
+
}
|
|
77
|
+
var GtmProvider = class {
|
|
78
|
+
constructor(client) {
|
|
79
|
+
this.client = client;
|
|
80
|
+
}
|
|
81
|
+
client;
|
|
82
|
+
id = "gtm";
|
|
83
|
+
capabilities() {
|
|
84
|
+
return { serverDryRun: false, reporting: false };
|
|
85
|
+
}
|
|
86
|
+
async listAccounts() {
|
|
87
|
+
const accounts = [];
|
|
88
|
+
const seen = /* @__PURE__ */ new Set();
|
|
89
|
+
let pageToken;
|
|
90
|
+
do {
|
|
91
|
+
const response = await this.client.request("accounts", "GET", void 0, pageToken ? { pageToken } : {});
|
|
92
|
+
for (const account of response.account ?? []) accounts.push({ provider: this.id, id: numeric(account.accountId), name: String(account.name ?? account.accountId) });
|
|
93
|
+
pageToken = response.nextPageToken;
|
|
94
|
+
if (pageToken && seen.has(pageToken)) throw new AdportError2("PROVIDER_ERROR", "GTM repeated an account pagination token.");
|
|
95
|
+
if (pageToken) seen.add(pageToken);
|
|
96
|
+
} while (pageToken);
|
|
97
|
+
return accounts;
|
|
98
|
+
}
|
|
99
|
+
async report(_query) {
|
|
100
|
+
throw new AdportError2("INVALID_INPUT", "GTM exposes tracking configuration. Use Google Ads or GA4 for performance metrics.");
|
|
101
|
+
}
|
|
102
|
+
read(accountId, suffix, query) {
|
|
103
|
+
return this.client.request(`accounts/${numeric(accountId)}${suffix}`, "GET", void 0, query);
|
|
104
|
+
}
|
|
105
|
+
async workspaceStatus(accountId, containerId, workspaceId) {
|
|
106
|
+
const base = `/containers/${numeric(containerId)}/workspaces/${numeric(workspaceId)}`;
|
|
107
|
+
const workspace = await this.read(accountId, base);
|
|
108
|
+
const status = await this.read(accountId, `${base}/status`);
|
|
109
|
+
const workspace_hash = createHash("sha256").update(JSON.stringify(stable({ workspace, status }))).digest("hex");
|
|
110
|
+
return { workspace, status, workspace_hash };
|
|
111
|
+
}
|
|
112
|
+
async plan(op) {
|
|
113
|
+
if (op.provider !== this.id || !(op.tool in gtmWriteSchemas)) throw new AdportError2("INVALID_INPUT", "Unsupported GTM operation.");
|
|
114
|
+
const parsed = gtmWriteSchemas[op.tool].safeParse(op.payload);
|
|
115
|
+
if (!parsed.success) throw new AdportError2("INVALID_INPUT", "Invalid GTM configuration.", parsed.error.issues);
|
|
116
|
+
const p = parsed.data;
|
|
117
|
+
const account = numeric(op.accountId);
|
|
118
|
+
const container = `accounts/${account}/containers/${numeric(p.container_id)}`;
|
|
119
|
+
let path = `${container}/workspaces`;
|
|
120
|
+
let method = "POST";
|
|
121
|
+
let body;
|
|
122
|
+
const query = {};
|
|
123
|
+
const changes = [];
|
|
124
|
+
if (op.tool === "gtm_create_workspace") {
|
|
125
|
+
await this.client.request(container);
|
|
126
|
+
body = { name: p.name, ...p.description === void 0 ? {} : { description: p.description } };
|
|
127
|
+
} else if (op.tool === "gtm_publish_version") {
|
|
128
|
+
path = `${container}/versions/${numeric(p.version_id)}`;
|
|
129
|
+
const version = await this.client.request(path);
|
|
130
|
+
assertFingerprint(version, p.expected_fingerprint);
|
|
131
|
+
let liveId = "0";
|
|
132
|
+
try {
|
|
133
|
+
liveId = String((await this.client.request(`${container}/versions:live`)).containerVersionId);
|
|
134
|
+
} catch (error) {
|
|
135
|
+
if (!(error instanceof AdportError2 && error.details && error.details.status === 404)) throw error;
|
|
136
|
+
}
|
|
137
|
+
if (liveId !== p.expected_live_version_id) throw new AdportError2("PENDING_MISMATCH", "The live GTM version changed. Review the published configuration and preview again.");
|
|
138
|
+
path += ":publish";
|
|
139
|
+
query.fingerprint = String(p.expected_fingerprint);
|
|
140
|
+
changes.push(`Publish complete version ${p.version_id}, replacing live version ${liveId}.`, JSON.stringify(version));
|
|
141
|
+
} else {
|
|
142
|
+
path += `/${numeric(p.workspace_id)}`;
|
|
143
|
+
if (op.tool === "gtm_create_version") {
|
|
144
|
+
const snapshot = await this.workspaceStatus(account, numeric(p.container_id), numeric(p.workspace_id));
|
|
145
|
+
if (snapshot.workspace_hash !== p.expected_workspace_hash) throw new AdportError2("PENDING_MISMATCH", "Workspace changes differ from the reviewed snapshot. Read gtm_workspace_status and preview again.");
|
|
146
|
+
if (Array.isArray(snapshot.status.mergeConflict) && snapshot.status.mergeConflict.length) throw new AdportError2("POLICY_VIOLATION", "Resolve GTM workspace conflicts before creating a version.");
|
|
147
|
+
path += ":create_version";
|
|
148
|
+
body = { name: p.name, ...p.notes === void 0 ? {} : { notes: p.notes } };
|
|
149
|
+
changes.push("Save ALL workspace changes; Google replaces the workspace. This does not publish.", JSON.stringify(snapshot.status));
|
|
150
|
+
} else {
|
|
151
|
+
const entity = op.tool.split("_").at(-1);
|
|
152
|
+
path += `/${entity === "variable" ? "variables" : `${entity}s`}`;
|
|
153
|
+
body = p[entity];
|
|
154
|
+
if (op.tool.startsWith("gtm_update_")) {
|
|
155
|
+
path += `/${numeric(p[`${entity}_id`])}`;
|
|
156
|
+
method = "PUT";
|
|
157
|
+
const current = await this.client.request(path);
|
|
158
|
+
assertFingerprint(current, p.expected_fingerprint);
|
|
159
|
+
query.fingerprint = String(p.expected_fingerprint);
|
|
160
|
+
body = { ...current, ...body };
|
|
161
|
+
changes.push(`Before: ${JSON.stringify(current)}`);
|
|
162
|
+
} else await this.client.request(`${container}/workspaces/${numeric(p.workspace_id)}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (body) changes.push(`After: ${JSON.stringify(body)}`);
|
|
166
|
+
const preview = {
|
|
167
|
+
summary: `${op.tool.replaceAll("_", " ")} in GTM account ${account}`,
|
|
168
|
+
changes,
|
|
169
|
+
coercions: [],
|
|
170
|
+
budgetDeltas: [],
|
|
171
|
+
serverValidated: false
|
|
172
|
+
};
|
|
173
|
+
return { path, method, body, query, preview };
|
|
174
|
+
}
|
|
175
|
+
async previewWrite(op) {
|
|
176
|
+
return (await this.plan(op)).preview;
|
|
177
|
+
}
|
|
178
|
+
async applyWrite(op) {
|
|
179
|
+
const plan = await this.plan(op);
|
|
180
|
+
const result = await this.client.request(plan.path, plan.method, plan.body, plan.query);
|
|
181
|
+
if (result.compilerError || result.syncStatus?.mergeConflict || result.syncStatus?.syncError) {
|
|
182
|
+
throw new AdportError2("PROVIDER_ERROR", "GTM returned compiler or synchronization errors. Inspect the workspace/version before retrying.");
|
|
183
|
+
}
|
|
184
|
+
const resource = result.containerVersion ?? result;
|
|
185
|
+
return { applied: true, resourceIds: [String(resource.path ?? plan.path)], details: result };
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
// src/index.ts
|
|
190
|
+
import { gtmTools as gtmTools2, GTM_SCOPES } from "@adport/core";
|
|
191
|
+
async function resolveGtmCredentials(store) {
|
|
192
|
+
const data = (await store.get("gtm"))?.data;
|
|
193
|
+
if (data?.client_id && data.client_secret && data.refresh_token) return {
|
|
194
|
+
clientId: data.client_id,
|
|
195
|
+
clientSecret: data.client_secret,
|
|
196
|
+
refreshToken: data.refresh_token
|
|
197
|
+
};
|
|
198
|
+
if (process.env.GTM_CLIENT_ID && process.env.GTM_CLIENT_SECRET && process.env.GTM_REFRESH_TOKEN) return {
|
|
199
|
+
clientId: process.env.GTM_CLIENT_ID,
|
|
200
|
+
clientSecret: process.env.GTM_CLIENT_SECRET,
|
|
201
|
+
refreshToken: process.env.GTM_REFRESH_TOKEN
|
|
202
|
+
};
|
|
203
|
+
return void 0;
|
|
204
|
+
}
|
|
205
|
+
async function createGtmModule(store) {
|
|
206
|
+
const credentials = await resolveGtmCredentials(store);
|
|
207
|
+
if (!credentials) return void 0;
|
|
208
|
+
const provider = new GtmProvider(new GtmClient(credentials));
|
|
209
|
+
return { provider, tools: gtmTools(provider) };
|
|
210
|
+
}
|
|
211
|
+
export {
|
|
212
|
+
GTM_API_BASE,
|
|
213
|
+
GTM_SCOPES,
|
|
214
|
+
GtmClient,
|
|
215
|
+
GtmProvider,
|
|
216
|
+
createGtmModule,
|
|
217
|
+
gtmTools2 as gtmTools,
|
|
218
|
+
resolveGtmCredentials
|
|
219
|
+
};
|
|
220
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/client.ts","../src/provider.ts"],"sourcesContent":["import { gtmTools, type CredentialStore, type ProviderModule } from '@adport/core';\nimport { GtmClient, type GtmCredentials } from './client.js';\nimport { GtmProvider } from './provider.js';\nexport { GtmClient, GTM_API_BASE, type GtmCredentials } from './client.js';\nexport { GtmProvider } from './provider.js';\nexport { gtmTools, GTM_SCOPES } from '@adport/core';\n\nexport async function resolveGtmCredentials(store: CredentialStore): Promise<GtmCredentials | undefined> {\n const data = (await store.get('gtm'))?.data;\n if (data?.client_id && data.client_secret && data.refresh_token) return {\n clientId: data.client_id, clientSecret: data.client_secret, refreshToken: data.refresh_token,\n };\n if (process.env.GTM_CLIENT_ID && process.env.GTM_CLIENT_SECRET && process.env.GTM_REFRESH_TOKEN) return {\n clientId: process.env.GTM_CLIENT_ID, clientSecret: process.env.GTM_CLIENT_SECRET, refreshToken: process.env.GTM_REFRESH_TOKEN,\n };\n return undefined;\n}\nexport async function createGtmModule(store: CredentialStore): Promise<ProviderModule | undefined> {\n const credentials = await resolveGtmCredentials(store);\n if (!credentials) return undefined;\n const provider = new GtmProvider(new GtmClient(credentials));\n return { provider, tools: gtmTools(provider) };\n}\n","import { AdportError } from '@adport/core';\n\nexport interface GtmCredentials { clientId: string; clientSecret: string; refreshToken: string }\nexport type GtmResource = Record<string, unknown>;\nexport const GTM_API_BASE = 'https://tagmanager.googleapis.com/tagmanager/v2';\nconst resourcePaths = [\n /^accounts$/,\n /^accounts\\/\\d+\\/containers$/,\n /^accounts\\/\\d+\\/containers\\/\\d+(?::snippet)?$/,\n /^accounts\\/\\d+\\/containers\\/\\d+\\/workspaces$/,\n /^accounts\\/\\d+\\/containers\\/\\d+\\/workspaces\\/\\d+(?:\\/status|:create_version)?$/,\n /^accounts\\/\\d+\\/containers\\/\\d+\\/workspaces\\/\\d+\\/(?:tags|triggers|variables)(?:\\/\\d+)?$/,\n /^accounts\\/\\d+\\/containers\\/\\d+\\/version_headers$/,\n /^accounts\\/\\d+\\/containers\\/\\d+\\/versions:live$/,\n /^accounts\\/\\d+\\/containers\\/\\d+\\/versions\\/\\d+(?::publish)?$/,\n];\n\n/** Fixed-origin REST client. Paths are constructed from validated numeric IDs, never caller URLs. */\nexport class GtmClient {\n private accessToken?: { token: string; expiresAt: number };\n constructor(private readonly credentials: GtmCredentials, private readonly fetchImpl: typeof fetch = fetch) {}\n\n async request(path: string, method = 'GET', body?: unknown, query: Record<string, string> = {}): Promise<GtmResource> {\n if (!resourcePaths.some(pattern => pattern.test(path))) {\n throw new AdportError('INVALID_INPUT', 'Invalid Google Tag Manager resource path.');\n }\n if (!this.accessToken || this.accessToken.expiresAt <= Date.now()) {\n const response = await this.fetchImpl('https://oauth2.googleapis.com/token', {\n method: 'POST', redirect: 'error', headers: { 'content-type': 'application/x-www-form-urlencoded' },\n body: new URLSearchParams({ client_id: this.credentials.clientId, client_secret: this.credentials.clientSecret,\n refresh_token: this.credentials.refreshToken, grant_type: 'refresh_token' }),\n });\n const token = await response.json().catch(() => ({})) as { access_token?: string; expires_in?: number };\n if (!response.ok || !token.access_token) throw new AdportError('PROVIDER_ERROR', 'Google Tag Manager authorization expired or was revoked. Reconnect GTM.');\n this.accessToken = { token: token.access_token, expiresAt: Date.now() + (Number(token.expires_in ?? 3600) - 60) * 1000 };\n }\n const params = new URLSearchParams(query);\n const response = await this.fetchImpl(`${GTM_API_BASE}/${path}${params.size ? `?${params}` : ''}`, {\n method, redirect: 'error', headers: { authorization: `Bearer ${this.accessToken.token}`, 'content-type': 'application/json' },\n ...(body === undefined ? {} : { body: JSON.stringify(body) }),\n });\n const result = await response.json().catch(() => ({})) as GtmResource;\n // Upstream response bodies may contain custom code or private configuration.\n if (!response.ok) throw new AdportError('PROVIDER_ERROR', `Google Tag Manager API request failed (HTTP ${response.status}). Check GTM permissions, API enablement and the requested resource.`, { status: response.status });\n return result;\n }\n}\n","import { createHash } from 'node:crypto';\nimport { AdportError, gtmWriteSchemas, type AdProvider, type Account, type NormalizedQuery, type Report,\n type WriteOperation, type WritePreview, type WriteResult } from '@adport/core';\nimport { GtmClient, type GtmResource } from './client.js';\n\nfunction numeric(value: unknown): string {\n if (typeof value !== 'string' || !/^\\d+$/.test(value)) throw new AdportError('INVALID_INPUT', 'GTM IDs must be numeric strings.');\n return value;\n}\nfunction stable(value: unknown): unknown {\n if (Array.isArray(value)) return value.map(stable);\n if (value && typeof value === 'object') return Object.fromEntries(Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([key, item]) => [key, stable(item)]));\n return value;\n}\nfunction assertFingerprint(resource: GtmResource, expected: unknown) {\n if (!expected || resource.fingerprint !== expected) throw new AdportError('PENDING_MISMATCH', 'GTM configuration changed. Read the resource and preview again.');\n}\n\nexport class GtmProvider implements AdProvider {\n readonly id = 'gtm';\n constructor(private readonly client: GtmClient) {}\n capabilities() { return { serverDryRun: false, reporting: false }; }\n async listAccounts(): Promise<Account[]> {\n const accounts: Account[] = [];\n const seen = new Set<string>();\n let pageToken: string | undefined;\n do {\n const response = await this.client.request('accounts', 'GET', undefined, pageToken ? { pageToken } : {});\n for (const account of (response.account ?? []) as GtmResource[]) accounts.push({ provider: this.id, id: numeric(account.accountId), name: String(account.name ?? account.accountId) });\n pageToken = response.nextPageToken as string | undefined;\n if (pageToken && seen.has(pageToken)) throw new AdportError('PROVIDER_ERROR', 'GTM repeated an account pagination token.');\n if (pageToken) seen.add(pageToken);\n } while (pageToken);\n return accounts;\n }\n async report(_query: NormalizedQuery): Promise<Report> {\n throw new AdportError('INVALID_INPUT', 'GTM exposes tracking configuration. Use Google Ads or GA4 for performance metrics.');\n }\n read(accountId: string, suffix: string, query?: Record<string, string>): Promise<GtmResource> {\n return this.client.request(`accounts/${numeric(accountId)}${suffix}`, 'GET', undefined, query);\n }\n async workspaceStatus(accountId: string, containerId: string, workspaceId: string) {\n const base = `/containers/${numeric(containerId)}/workspaces/${numeric(workspaceId)}`;\n const workspace = await this.read(accountId, base);\n const status = await this.read(accountId, `${base}/status`);\n const workspace_hash = createHash('sha256').update(JSON.stringify(stable({ workspace, status }))).digest('hex');\n return { workspace, status, workspace_hash };\n }\n private async plan(op: WriteOperation) {\n if (op.provider !== this.id || !(op.tool in gtmWriteSchemas)) throw new AdportError('INVALID_INPUT', 'Unsupported GTM operation.');\n const parsed = gtmWriteSchemas[op.tool as keyof typeof gtmWriteSchemas].safeParse(op.payload);\n if (!parsed.success) throw new AdportError('INVALID_INPUT', 'Invalid GTM configuration.', parsed.error.issues);\n const p = parsed.data as Record<string, unknown>;\n const account = numeric(op.accountId);\n const container = `accounts/${account}/containers/${numeric(p.container_id)}`;\n let path = `${container}/workspaces`;\n let method = 'POST';\n let body: unknown;\n const query: Record<string, string> = {};\n const changes: string[] = [];\n if (op.tool === 'gtm_create_workspace') {\n await this.client.request(container);\n body = { name: p.name, ...(p.description === undefined ? {} : { description: p.description }) };\n } else if (op.tool === 'gtm_publish_version') {\n path = `${container}/versions/${numeric(p.version_id)}`;\n const version = await this.client.request(path);\n assertFingerprint(version, p.expected_fingerprint);\n let liveId = '0';\n try { liveId = String((await this.client.request(`${container}/versions:live`)).containerVersionId); }\n catch (error) { if (!(error instanceof AdportError && error.details && (error.details as { status?: number }).status === 404)) throw error; }\n if (liveId !== p.expected_live_version_id) throw new AdportError('PENDING_MISMATCH', 'The live GTM version changed. Review the published configuration and preview again.');\n path += ':publish'; query.fingerprint = String(p.expected_fingerprint);\n changes.push(`Publish complete version ${p.version_id}, replacing live version ${liveId}.`, JSON.stringify(version));\n } else {\n path += `/${numeric(p.workspace_id)}`;\n if (op.tool === 'gtm_create_version') {\n const snapshot = await this.workspaceStatus(account, numeric(p.container_id), numeric(p.workspace_id));\n if (snapshot.workspace_hash !== p.expected_workspace_hash) throw new AdportError('PENDING_MISMATCH', 'Workspace changes differ from the reviewed snapshot. Read gtm_workspace_status and preview again.');\n if (Array.isArray(snapshot.status.mergeConflict) && snapshot.status.mergeConflict.length) throw new AdportError('POLICY_VIOLATION', 'Resolve GTM workspace conflicts before creating a version.');\n path += ':create_version'; body = { name: p.name, ...(p.notes === undefined ? {} : { notes: p.notes }) };\n changes.push('Save ALL workspace changes; Google replaces the workspace. This does not publish.', JSON.stringify(snapshot.status));\n } else {\n const entity = op.tool.split('_').at(-1)!;\n path += `/${entity === 'variable' ? 'variables' : `${entity}s`}`;\n body = p[entity];\n if (op.tool.startsWith('gtm_update_')) {\n path += `/${numeric(p[`${entity}_id`])}`; method = 'PUT';\n const current = await this.client.request(path);\n assertFingerprint(current, p.expected_fingerprint);\n query.fingerprint = String(p.expected_fingerprint);\n // Preserve fields outside the supported editable schema, including sequencing and consent.\n body = { ...current, ...(body as GtmResource) };\n changes.push(`Before: ${JSON.stringify(current)}`);\n } else await this.client.request(`${container}/workspaces/${numeric(p.workspace_id)}`);\n }\n }\n if (body) changes.push(`After: ${JSON.stringify(body)}`);\n const preview: WritePreview = { summary: `${op.tool.replaceAll('_', ' ')} in GTM account ${account}`, changes,\n coercions: [], budgetDeltas: [], serverValidated: false };\n return { path, method, body, query, preview };\n }\n async previewWrite(op: WriteOperation): Promise<WritePreview> { return (await this.plan(op)).preview; }\n async applyWrite(op: WriteOperation): Promise<WriteResult> {\n const plan = await this.plan(op);\n const result = await this.client.request(plan.path, plan.method, plan.body, plan.query);\n if (result.compilerError || (result.syncStatus as GtmResource | undefined)?.mergeConflict || (result.syncStatus as GtmResource | undefined)?.syncError) {\n throw new AdportError('PROVIDER_ERROR', 'GTM returned compiler or synchronization errors. Inspect the workspace/version before retrying.');\n }\n const resource = (result.containerVersion ?? result) as GtmResource;\n return { applied: true, resourceIds: [String(resource.path ?? plan.path)], details: result };\n }\n}\n"],"mappings":";AAAA,SAAS,gBAA2D;;;ACApE,SAAS,mBAAmB;AAIrB,IAAM,eAAe;AAC5B,IAAM,gBAAgB;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAGO,IAAM,YAAN,MAAgB;AAAA,EAErB,YAA6B,aAA8C,YAA0B,OAAO;AAA/E;AAA8C;AAAA,EAAkC;AAAA,EAAhF;AAAA,EAA8C;AAAA,EADnE;AAAA,EAGR,MAAM,QAAQ,MAAc,SAAS,OAAO,MAAgB,QAAgC,CAAC,GAAyB;AACpH,QAAI,CAAC,cAAc,KAAK,aAAW,QAAQ,KAAK,IAAI,CAAC,GAAG;AACtD,YAAM,IAAI,YAAY,iBAAiB,2CAA2C;AAAA,IACpF;AACA,QAAI,CAAC,KAAK,eAAe,KAAK,YAAY,aAAa,KAAK,IAAI,GAAG;AACjE,YAAMA,YAAW,MAAM,KAAK,UAAU,uCAAuC;AAAA,QAC3E,QAAQ;AAAA,QAAQ,UAAU;AAAA,QAAS,SAAS,EAAE,gBAAgB,oCAAoC;AAAA,QAClG,MAAM,IAAI,gBAAgB;AAAA,UAAE,WAAW,KAAK,YAAY;AAAA,UAAU,eAAe,KAAK,YAAY;AAAA,UAChG,eAAe,KAAK,YAAY;AAAA,UAAc,YAAY;AAAA,QAAgB,CAAC;AAAA,MAC/E,CAAC;AACD,YAAM,QAAQ,MAAMA,UAAS,KAAK,EAAE,MAAM,OAAO,CAAC,EAAE;AACpD,UAAI,CAACA,UAAS,MAAM,CAAC,MAAM,aAAc,OAAM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AK,IAAI;AACvC,MAAI,MAAM,aAAa,KAAK,iBAAiB,KAAK,cAAe,QAAO;AAAA,IACtE,UAAU,KAAK;AAAA,IAAW,cAAc,KAAK;AAAA,IAAe,cAAc,KAAK;AAAA,EACjF;AACA,MAAI,QAAQ,IAAI,iBAAiB,QAAQ,IAAI,qBAAqB,QAAQ,IAAI,kBAAmB,QAAO;AAAA,IACtG,UAAU,QAAQ,IAAI;AAAA,IAAe,cAAc,QAAQ,IAAI;AAAA,IAAmB,cAAc,QAAQ,IAAI;AAAA,EAC9G;AACA,SAAO;AACT;AACA,eAAsB,gBAAgB,OAA6D;AACjG,QAAM,cAAc,MAAM,sBAAsB,KAAK;AACrD,MAAI,CAAC,YAAa,QAAO;AACzB,QAAM,WAAW,IAAI,YAAY,IAAI,UAAU,WAAW,CAAC;AAC3D,SAAO,EAAE,UAAU,OAAO,SAAS,QAAQ,EAAE;AAC/C;","names":["response","AdportError","gtmTools"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adport/provider-gtm",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"description": "Google Tag Manager API provider for adport",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"zod": "^4.4.3",
|
|
20
|
+
"@adport/core": "0.9.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/node": "^26.1.2",
|
|
24
|
+
"tsup": "^8.3.0",
|
|
25
|
+
"typescript": "^5.8.0",
|
|
26
|
+
"vitest": "^4.1.10"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/ynnickw/adport.git",
|
|
31
|
+
"directory": "packages/gtm"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/ynnickw/adport#readme",
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/ynnickw/adport/issues"
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=22.13"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsup src/index.ts --format esm --dts --sourcemap --clean",
|
|
45
|
+
"test": "vitest run",
|
|
46
|
+
"typecheck": "tsc --noEmit"
|
|
47
|
+
}
|
|
6
48
|
}
|