@internetarchive/ia-book-actions 1.4.2 → 1.4.3-alpha-adminsticky

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.
@@ -12,6 +12,10 @@ on:
12
12
  - synchronize
13
13
  - closed
14
14
 
15
+ permissions:
16
+ contents: write
17
+ pull-requests: write
18
+
15
19
  concurrency: preview-${{ github.ref }}
16
20
 
17
21
  env:
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  },
8
8
  "author": "Internet Archive",
9
9
  "license": "AGPL-3.0-only",
10
- "version": "1.4.2",
10
+ "version": "1.4.3-alpha-adminsticky",
11
11
  "main": "index.js",
12
12
  "module": "index.js",
13
13
  "publishConfig": {
@@ -31,7 +31,6 @@
31
31
  "@internetarchive/local-cache": "^0.2.1",
32
32
  "@internetarchive/modal-manager": "^2.0.0",
33
33
  "@internetarchive/shared-resize-observer": "^0.2.0",
34
- "install-deps": "^1.1.0",
35
34
  "lit": "^2.8.0 || ^3.3.2"
36
35
  },
37
36
  "devDependencies": {
@@ -409,6 +409,7 @@ export default class ActionsHandler extends LitElement {
409
409
  */
410
410
  setStickyAdminAccess(value) {
411
411
  const domain = window.location.hostname === 'localhost' ? 'localhost' : '.archive.org';
412
- Cookies.setItem('sticky-admin-access', value, '', '/', domain);
412
+ const expires = new Date(Date.now() + 30 * 24 * 60 * 60 * 1000); // 30 days from now
413
+ Cookies.setItem('sticky-admin-access', value, expires, '/', domain);
413
414
  }
414
415
  }
@@ -0,0 +1,91 @@
1
+ import { expect, fixture } from '@open-wc/testing';
2
+ import sinon from 'sinon';
3
+
4
+ import ActionsHandler from '../../../src/core/services/actions-handler/actions-handler.js';
5
+
6
+ // Define a temporary tag for this element for testing
7
+ const TEST_TAG = 'ia-actions-handler-test';
8
+ if (!customElements.get(TEST_TAG)) {
9
+ customElements.define(TEST_TAG, ActionsHandler);
10
+ }
11
+
12
+ describe('ActionsHandler#setStickyAdminAccess', () => {
13
+ let clock;
14
+ let lastSetCookie;
15
+ let cookieOverridden = false;
16
+ let actionsHandlerFixture;
17
+
18
+ beforeEach(async () => {
19
+ // Intercept document.cookie writes to capture the full cookie string
20
+ Object.defineProperty(document, 'cookie', {
21
+ configurable: true,
22
+ get() {
23
+ return '';
24
+ },
25
+ set(value) {
26
+ lastSetCookie = value;
27
+ },
28
+ });
29
+ cookieOverridden = true;
30
+
31
+ // Create the element via fixture (portable across browsers)
32
+ actionsHandlerFixture = await fixture(`<${TEST_TAG}></${TEST_TAG}>`);
33
+ });
34
+
35
+ afterEach(() => {
36
+ sinon.restore();
37
+ if (clock) {
38
+ clock.restore();
39
+ clock = undefined;
40
+ }
41
+ // restore document.cookie
42
+ if (cookieOverridden) {
43
+ try {
44
+ // remove our instance-level override
45
+ // eslint-disable-next-line no-param-reassign
46
+ delete document.cookie;
47
+ } catch (e) {
48
+ // ignore
49
+ }
50
+ cookieOverridden = false;
51
+ }
52
+ lastSetCookie = undefined;
53
+ });
54
+
55
+ it('sets the sticky-admin-access cookie with correct domain, path, and 30-day expiration', async () => {
56
+ // Arrange: fix time and stub cookie writer
57
+ const now = new Date('2025-01-01T00:00:00.000Z');
58
+ clock = sinon.useFakeTimers({ now: now.getTime() });
59
+
60
+ // Calculate expected values based on current environment
61
+ const expectedDomain = window.location.hostname === 'localhost' ? 'localhost' : '.archive.org';
62
+ const expectedExpires = new Date(now.getTime() + 30 * 24 * 60 * 60 * 1000);
63
+
64
+ // Act: call the method on the element created in beforeEach
65
+ actionsHandlerFixture.setStickyAdminAccess(true);
66
+
67
+ // Assert: verify the composed cookie string
68
+ expect(lastSetCookie).to.be.a('string');
69
+ // Name and value
70
+ expect(lastSetCookie).to.contain(`${encodeURIComponent('sticky-admin-access')}=${encodeURIComponent('true')}`);
71
+ // Domain
72
+ expect(lastSetCookie).to.contain(`domain=${expectedDomain}`);
73
+ // Path
74
+ expect(lastSetCookie).to.contain('path=/');
75
+ // Expiration close to 30 days from now
76
+ const match = /expires=([^;]+)/.exec(lastSetCookie);
77
+ expect(match).to.not.equal(null);
78
+ const expiresStr = match && match[1];
79
+ const parsed = expiresStr ? new Date(expiresStr) : null;
80
+ expect(parsed).to.be.instanceOf(Date);
81
+ expect(parsed && parsed.getTime()).to.equal(expectedExpires.getTime());
82
+ });
83
+
84
+ it('sets the cookie value to false when disabling', async () => {
85
+ // Act
86
+ actionsHandlerFixture.setStickyAdminAccess(false);
87
+
88
+ expect(lastSetCookie).to.be.a('string');
89
+ expect(lastSetCookie).to.contain(`${encodeURIComponent('sticky-admin-access')}=${encodeURIComponent('false')}`);
90
+ });
91
+ });
@@ -1,16 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(yarn outdated *)",
5
- "Bash(gh pr *)",
6
- "Bash(git log *)",
7
- "mcp__plugin_atlassian_atlassian__getAccessibleAtlassianResources",
8
- "Bash(npm view *)",
9
- "mcp__plugin_atlassian_atlassian__searchJiraIssuesUsingJql",
10
- "Bash(xargs -I {} basename {})",
11
- "Bash(npm info *)",
12
- "mcp__plugin_atlassian_atlassian__getJiraIssue",
13
- "mcp__plugin_atlassian_atlassian__getJiraProjectIssueTypesMetadata"
14
- ]
15
- }
16
- }